1. Elements – sequence-series outputting

Write a program that prints the following elements: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19,
(hereto referred to as elements) etc., up till a user-entered value. The program should
not print more than 10 numbers per line. The last line printed may be less than 10.
Apart from the first number and the last number, there should be a “,” separating all
the numbers. The last number on every line should have a “.” after it. Before exiting
it should also prints the sum of all elements : Calculate the sum of the items and enter
the result. For instance if the user entered 76 your output should be as follows
A sample run of your program should be as follows:
Enter your number ( >= 1 and <= 100) : 76 
Your sequence is
1, 3, 5, 7, 9, 11, 13, 15, 17, 19.
21,23, 25, 27, 29, 31, 33, 35, 37, 39.
41,43, 45, 47, 49, 51, 53, 55, 57, 59.
61,63, 65, 67, 69, 71, 73, 75.
The sum of the above elements 1444
[25 pts.]
2. Calculation of area of rectangles
Write a program that calculates the area of a rectangle after a user has entered the
width and breadth ( dimensions of the rectangle). Test your program with the
following values: 3.57 as a width and 7 as a breadth, and then 3.40 as a width and 9
as a breadth for another rectangle. Your program should be able to handle more
than one rectangle before exiting . A run of your program should look like the
following:
Enter width for rectangle Nr. 1 >> 3.57
Enter breadth for rectangle Nr. 1 >> 7 
Are of rectangle Nr. 1 is : 24.99
University of Botswana, Department of Computer Science
Take-Home Exercises Nr. 2
Submission deadline : 6th October 2014, 1630 hours, via Moodle
Page 2 of 3
Enter width for rectangle Nr. 2 : 3.40
Enter width for rectangle Nr. 2 >> 3.4
Enter breadth for rectangle Nr. 2 >> 9 
Are of rectangle Nr. 2 is : 30.6
Enter width for rectangle Nr. 3 >> -1
Enter breadth for rectangle Nr. 3 >>5
Goodbye
Clearly if the user enters a negative number for any one of the dimensions then the program should end.
[20 pts.]
3. Finding Errors - Find all error(s) in the following program
class Volume {
public static void main ( String[] args) {
integer length, width, height;
length = 3;
volume = length * width * height;
System.out.println(“The volume is ”+volume);
}
} // end class Volume
[5 pts]
4. Legal Statements
Which of the following program statements are legal? And for those that are legal, state the values stored in the respective variables? Assume that each variable having the same name is being declared for the first time( in other words, assume each variable is unique)
i. int x = 4;
University of Botswana, Department of Computer Science
Take-Home Exercises Nr. 2
Submission deadline : 6th October 2014, 1630 hours, via Moodle
Page 3 of 3
ii. int x =456;
iii. int x = (int) 4.56;
iv. int z = 2.1;
v. double x = 5.7723;
vi. double a = (int) 5.7723;
vii. double x = 6;
viii. double figures = true;
ix. char c = “hello”;
x. char c = “”;
xi. char c = ‘&’;
xii. boolean a = true;
xiii. boolean value = true && false;
xiv. Boolean A = ( A == a);
xv. String t = ‘Hey you’;
xvi. String t = “Hello”;
xvii. String t = “+7.33”;
xviii. String text = 7.33;
xix. short sht = 32767 + 1;
xx. int init = -2147483648-1;
[ ½ each . total 10 pts ]
5. Calculation of tax in Ruritania
In a fictitious country of Ruritania, which is in a fictitious continent called Afrisia, the tax system is highly simplified. They have system where all taxes are converted to one single value and then the tax is applied according to the following rule(s): if a person earns less than ZB10,000.00 then you pay 10% tax on all income, and if it is >= ZB10,000.00, then you pay 10% on the first ZB 10,000 zubies ( ZB, the unit of currency in Ruritania, and 30% tax on the rest of your income.
(a) Write a pseudo-code for the tax calculation in Ruritania
(b) Convert your pseudo-code in (a) into an equivalent flow chart
(c) Write a program in Java, that calculates and prints how many million zubies to be paid in taxes.
[5, 5, 10 ( 20 pts.) ]