Ics 2201 Object Oriented Programming II
Ics 2201 Object Oriented Programming II
Instructions to Candidates:
You should have the following for this examination
- Answer Booklet
This paper consist of FIVE questions
Answer question ONE (COMPULSORY) and any other TWO questions
Maximum marks for each part of a question are as shown
This paper consists of THREE printed pages
b) Write a Java code to enter two integers and test the two integers to see if the large value entered is
exactly divisible by the smaller value. You must ensure that both values entered by the user must
be greater than zero, and then check to see which of the value is larger. Assume that a and b are
the two values entered by the user, write a code to perform the above task. (9 marks)
© 2012 – The Mombasa Polytechnic University College Page 1
c) Give an appropriate example for each of the following data types char, int, float, string.
(4 marks)
int a, b;
for (a = 1 ; a <3; ++ a)
{
For (b = 1; b < =3; ++b)
system.out.printin (a + b);
system.out.printin (“ ∖ n );
}
b) Write the output that was produced by the following Java code. (10 marks)
Int a, b;
for (a = 1; a<=a;a++)
{
For (b – 1; b< =a; b++)
system.out.print (“*”);
system.out.print (“ ∖ n );
}
Question Three
a) Write a program that iterates through the odd numbers less than 30 and outputs the square of each
number using for loop. (12 marks)
c) Name the FOUR methods that are included in every applet. (4 marks)
Question Four
a) Write a Java code that required the user to input an integer between 1 to 100. Using a nested if,
check that the integer is within this range. If so, determine whether the integer is greater than or
less than 50. (12 marks)
(ii) State which of the following are valid or invalid variable names, members, switch, 1BEE, price
$, employee – name. (5 marks)
b) Write an applet program, to display the message “student Enrolment system” in blue color using
the drawstring () method. (10 marks)