Past Paper - IP Phase Test 1
Past Paper - IP Phase Test 1
Select the most appropriate answer for the questions given below:
1. Which one of the following is correct with respect to the features of Java
Programming Language?
(a) init
(b) main
(c) paint
(d) showMessageDialog
4. What will be the result of the expression a % b when a and b are of type
int and their values are a = 10 and b = 6?
(a) 1.66
(b) 1
(c) 4
(d) None of the above.
[5 marks]
Section B
1. All variables must be given a type when they are declared. (TRUE)
3. By convention, all classes start with lower case first letter. (FALSE)
Eg JOptionPane, Graphics g
[6 marks]
Section C
r = MattPow(p,2) = q; OR
r = p*p + q;
4. Test if the value of the variable count is greater than 10. If it is, print
“Count is greater than 10”.
[4 marks]
Section D
Identify and correct the errors in each of the following sets of code
1. x = 1;
while (x >=4)
x ++; = x++; x = x+ 1;
2. If (gender == 1)
System.out.println(“Women”);
else;
Syste.out.println(“Men”);
If (gender == 1)
System.out.println(“Women”);
else
System.out.println(“Men”);
x = x * counter;
}
[3 marks]
Section E
1. Carefully read the following program and answer the following questions
below:
public class MainClass {
public static void main(String[] arg) {
int limit = 10;
int sum = 0;
for (int i = 1; i <= limit; i++) {
if (i % 3 != 0)
sum = sum + i;
}
System.out.println(sum);
}
}
= 1 + 2 + 4 + 5 + 7 + 8 + 10
= 37
[2 marks]
(b) How many times the statement “sum = sum + I;” will execute?
= 7 times
[2 marks]
2. Identify the class, package, object, method and variable from the
highlighted words of the program below:
// Maximum.java
// Finding the maximum of three doubles
import java.awt.Container;
import javax.swing.*;
String s1 = JOptionPane.showInputDialog(
"Enter first floating-point value" );
String s2 = JOptionPane.showInputDialog(
"Enter second floating-point value" );
String s3 = JOptionPane.showInputDialog(
"Enter third floating-point value" );
java.awt = package
init() = method
showInputDialog =
JOptionPane = class
number2 = variable
c = variable
(6 marks)
Section F
1. Develop and run a Java Application or Java Applet that accepts student
scores (0 to 100) from a user through an input box and displays the
summary as shown below. Pass mark is 50 and above.
Number failed 1
Number passed 9
(12 marks)