0% found this document useful (0 votes)
39 views6 pages

Ipl Dics Aug 16

This document contains an examination question paper for the subject "Introduction to Programming Languages". It consists of 8 questions worth a total of 160 marks. The paper instructs candidates to answer any 5 out of the 8 questions. Each question provides instructions for candidates to write code, trace output, define classes, methods, or determine true/false statements related to programming languages and Java.

Uploaded by

Edwin Eragon
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
39 views6 pages

Ipl Dics Aug 16

This document contains an examination question paper for the subject "Introduction to Programming Languages". It consists of 8 questions worth a total of 160 marks. The paper instructs candidates to answer any 5 out of the 8 questions. Each question provides instructions for candidates to write code, trace output, define classes, methods, or determine true/false statements related to programming languages and Java.

Uploaded by

Edwin Eragon
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 6

DIPLOMA IN COMPUTER STUDIES

AUGUST 2016 EXAMINATION

INTRODUCTION TO PROGRAMMING LANGUAGES

SUBJECT CODE : 3CS0214

TIME ALLOWED : 3 HOURS

INSTRUCTIONS TO CANDIDATES :

1. Answer any FIVE (5) out of EIGHT (8) questions.


2. All questions carry equal marks.
3. This is closed-book examination. No books, notes, cell phones,
communication devices of any sort, or any other aids are permitted except
as stated otherwise
4. All answers must be written in the answer booklet provided.
5. The use of dictionaries is not allowed in the examination.

DO NOT REMOVE THIS EXAMINATION QUESTION PAPER FROM


THE EXAMINATION HALL

1
Answer any FIVE (5) out of EIGHT (8) questions

Question 1

Determine whether the following statements are TRUE (T) or FALSE (F).

(a) Java compiler produces an object file that contains bytecode.


TRUE / FALSE

(b) The ability to take more than one form is called encapsulation.
TRUE / FALSE

(c) iavac is the java compiler.


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

(f) Java supports operator overloading.


TRUE / FALSE

(g) Instance variables are declared inside a class.


TRUE / FALSE

(h) Java has a keyword called final.


TRUE / FALSE

(i) Constructor method can be overloaded.


TRUE / FALSE

(j) Java programming language is a fourth generation language.


TRUE / FALSE
(Total: 20 marks)

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

Using a loop construct, generate the following output:

=====
7777777
55555
4444
22
1
=====
(Total: 20 marks)

3
Question 4

Trace the output of the following program:

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

Write Java statements to accomplish the following tasks:

(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

Construct a class named ConvertToLowerCase with constructor, data members, setter,


getter and override the toString method so that the above code can be compiled and executed
successfully.

[Hint:- user toLowerCase() method in String class to convert text to Lower Case]

(Total: 20 marks)

Question 7

Consider the following numeric values stores in an array.

'C' '@' 'p' 'u' '*' 'S'

(a) Determine the size of the array.


(2 marks)

(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

Discuss FIVE (5) differences between a class and an object in Java.

(Total: 20 marks)

END OF EXAMINATION QUESTION PAPER

You might also like