Capability1 Assignment
Capability1 Assignment
Introduction:
This document covers list of assignments/exercises related to first capability of
Basecamp program:
Observations:
KO: 1. Ability to implement right program structure - initialize variables
KO: 2. Ability to work with different data types - String and primitive data types
KO: 3. Ability to work with Loop - while, do while and for loops
KO: 4. Ability to work with conditional statements - if else, else if ladder and switch case
5: Ability to do type-casting of both primitive and user defined objects
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
pg. 1
Basecamp Capability 1 Assignments
7x1=7
7 x2 = 14
.....
7 x 12 = 84
pg. 2
Basecamp Capability 1 Assignments
Input:
Input is a positive number
Output:
Output is a series of steps showing how it reached the number and then should return
total count of steps
Program 1: KeyboardUtil.java
import java.util.Scanner;
/**
*
* @param message
* message to print on console
* @return int fetched from keyboard
*/
public static int getInt(String message) {
System.out.println(message);
Scanner scanner = new Scanner(System.in);
return scanner.nextInt();
}
/**
*
* @param message
* message to print on console
* @return Double fetched from keyboard
*/
public static double getDouble(String message) {
System.out.println(message);
Scanner scanner = new Scanner(System.in);
return scanner.nextDouble();
}
pg. 3
Basecamp Capability 1 Assignments
/**
*
* @param message
* message to print on console
* @return String fetched from keyboard
*/
public static String getString(String message) {
System.out.println(message);
Scanner scanner = new Scanner(System.in);
return scanner.nextLine();
}
Program 2: KeyboardDemo.java
pg. 4
Basecamp Capability 1 Assignments
Output:
Error message if any of input is invalid otherwise Employee details
pg. 5
Basecamp Capability 1 Assignments
a=a+b;
b=b+10;
Print value of a and b
End
You have a green lottery ticket, with int a, b, and c on it. Write a method which returns
appropriate integer number based on following conditions:
If the numbers are all different from each other, the result is 0.
If all of the numbers are the same, the result is 20.
If two of the numbers are the same, the result is 10.
pg. 6
Basecamp Capability 1 Assignments
Write a program to make a pattern like a pyramid with a number which will repeat the
number in the same row
1
2 2
3 3 3
4 4 4 4
Write a program that reads a positive integer and count the number of digits the
number.
pg. 7
Basecamp Capability 1 Assignments
pg. 8
Basecamp Capability 1 Assignments
pg. 9
Basecamp Capability 1 Assignments
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Summary:
You must have learnt following concepts:
How to write a basic program?
How to declare primitive variables?
How to get input from console and display?
How to use conditional and iterative statements?
How to define functions/methods?
How to pass arguments to functions?
How to work with local variables?
How to do typecasting?
pg. 10