Ipl Dics Aug 16
Ipl Dics Aug 16
INSTRUCTIONS TO CANDIDATES :
1
Answer any FIVE (5) out of EIGHT (8) questions
Question 1
Determine whether the following statements are TRUE (T) or FALSE (F).
(b) The ability to take more than one form is called encapsulation.
TRUE / FALSE
(d) The Private modifier can be invoked only by a code in another class.
TRUE / FALSE
(e) Single quotes (' ') should be used when assigning a String value.
TRUE / FALSE
2
Question 2
(a) Re-write the following Java statement using the nested if-else construct:
boolean isSingle=true;
double income=3000;
String output;
output=(isSingle)?((income<=2500)?
"Qualified for BR1M":"Income is too high"):
"Must be single to get BR1M";
System.out.println(output);
(10 marks)
(b) Re-write the following Java statement using the if-else statement:
switch(race){
case 'M': case 'm':
System.out.println("Malay");
break;
case 'C': case 'c':
System.out.println("Chinese");
break;
case 'I': case 'i':
System.out.println("Indian");
break;
default:
System.out.println("Other");
break;
}
(10 marks)
(Total: 20 marks)
Question 3
=====
7777777
55555
4444
22
1
=====
(Total: 20 marks)
3
Question 4
class TestPrint{
public static void main(String[]args){
for(int i=0;i<10;i++){
for(int j=0;j<5;j++){
System.out.print(i*2 - ++j + "^^");
}
System.out.println();
}
}
}
(Total: 20 marks)
Question 5
(a) Declare a public class named ‘Product’. Then create two attributes named
‘productName’ of type string and another named ‘unitPrice’ if type double with
default access modifier.
(6 marks)
(b) The ‘Product’ class contains two constructors. One of the constructor with no
arguments and another constructor accepts a string named ‘productName’ and an
integer named ‘unitPrice’.
For the constructor with no argument, initialize the data members ‘productName’ to
empty string and ‘unitPrice’ with values zero (0). For the constructor with two
arguments, initialize the data members ‘sName’ and ‘uPrice’ with the values passed
into the constructor.
(10 marks)
(c) Override the toString method to return the information of the product which consists
of the product name and the price of the product after incurring 6% of GST.
(4 marks)
(Total: 20 marks)
4
Question 6
class TestToLowerCase{
public static void main (String[] args) {
ConvertToLowerCase s1 = new ConvertToLowerCase ("JOHNY");
ConvertToLowerCase s2 = new ConvertToLowerCase ("MACY");
s2.setText("BOBO");
System.out.print(s2.getText()+ ">>");
System.out.println(s2);
System.out.println();
System.out.print(s1.getText()+ ">>");
System.out.print(s1);
}
}
When the above code snippet is executed it produces the following output:
BOBO>>bobo
JOHNY>>johny
[Hint:- user toLowerCase() method in String class to convert text to Lower Case]
(Total: 20 marks)
Question 7
(b) Identify the values store in the first element of the array.
(2 marks)
(c) Identify the values store in the last element of the array.
(2 marks)
5
(d) Write a Java method accepting an array as a parameter. The method can determine
and display each of the elements in an array whether in alphabet or not.
[Hint:- upper case A to Z in java represented by integer values from between 65 to 90;
whether lower case a to z in java represented by integer values from 97 to 122.]
(14 marks)
(Total: 20 marks)
Question 8
(Total: 20 marks)