Você está na página 1de 6

NCC EDUCATION INTERNATIONAL DIPLOMA IN COMPUTER STUDIES JAVA DECEMBER 2012 LOCAL EXAMINATION

SECTION A Answer ALL questions in this section.

SECTION B Answer any TWO (2) questions in this section.

Time: 2 hours

Clearly cross out surplus answers. Failure to do this in Section B will result in only the first two answers being marked.

Any reference material brought into the examination room must be handed to the invigilator before the start of the examination.

Java

December 2012

Final

NCC Education Ltd 2012

SECTION A ANSWER ALL QUESTIONS IN THIS SECTION QUESTION 1 Differentiate between a class and an instance. Marks 4

QUESTION 2 What are program comments? (i) (ii) Identify the types of comments in the following program segment: //demonstrating comments /* this shows that these comments are different*/ /**everything is a Comment here.*/

1 3

QUESTION 3 Explain briefly the logic error with the following while repetition structure? Correct the error by amending the following code segment. int z=5, sum=0; while(z >= 0) sum+=z;

QUESTION 4 In each of the following Java statements, show the value of x after each statement is executed: x = 7 *2 + 2% 4 1; (i) (ii) x = 1234 % 1000 / 10 % 10;

2 2

QUESTION 5 Given the following statement, String[] deptName = {Accounting, Human Resources, Sales}; Write a Java statement to print these department names using for loop and length field.

QUESTION 6 Given int x = 5; int y=7; evaluate the following logical expression: (x=y) || (x!=y) (i) (ii) (x>y) && (x!=y)
Page 2 of 6
Java December 2012 Final

2 2

NCC Education Ltd 2012

QUESTION 7 Write a common escape sequence for the following description: (i) Backspace (ii) Form feed

Marks 1 1 1 1

(iii) Newline (iv) Backslash QUESTION 8 Explain briefly the following Thread class methods. start() (i) (ii) (iii) (iv) stop() isAlive() sleep(int)

1 1 1 1

QUESTION 9 Given the following statement, con.setLayout(new GridLayout(2, 3, 2, 4)); Explain the layout for con.

QUESTION 10 Briefly explain the following File class methods. i) boolean canRead() ii) iii) iv) Boolean exists() String getName() String getPath()

1 1 1 1

Total 40 Marks

Page 3 of 6
Java December 2012 Final NCC Education Ltd 2012

SECTION B ANSWER ANY TWO (2) QUESTIONS IN THIS SECTION QUESTION 11 a) (i) (ii) Explain the meaning of the private access field modifier. Create a class EventSite which has private data fields siteNumber, usageFee and managerName of integer, double and string type data. Construct a constructor that sets any EventSite siteNumber to 999, any usageFee to 0.0, and any managerName to ZZZ. Define mutator and accessor methods to set and get data for usageFee. Marks 2 4

(iii)

(iv) (v)

Define a class EventSites method usageFeeRaise which has the argument amt of double 5 data type. The method will raise the usageFee by the amount amt if the usageFee is less than 1000.00. It will return the usageFee value. Create an instant of EventSite object named onsite. 1 3

(vi)

(vii) Assign the value 500.00 to the usageFee of onsite and display the value using the class methods defined in part (iv). (viii) Use the method usageFeeRaise to raise the usageFee of onsite by 200.00 and then display the usageFee value of onsite. b) Given: public class Employee {} public class HourlyWorker extends Employee{} (i) (ii) (iii) What concept is illustrated by the above classes? Explain the concept in detail. Identify the classes in terms of the concept. Discuss the benefits of using the concept

2 2 3

Total 30 Marks

Page 4 of 6
Java December 2012 Final NCC Education Ltd 2012

QUESTION 12 a) (i) What is an array?

Marks 2 8

(ii) Create a class Employee with the data fields (empNum and empSal), a constructor and an accessor (get) method for each field. (iii) Declare an array named emp that holds seven Employees. (iv) Assume that you want to number your Employees as 0, 1, 2, and so on, and the salary of each employee is $500.00, construct seven Employee objects of the array emp. (v) Print the data for seven Employees stored in the emp array.

2 4

b) Write a method sumEven that returns the sum of the even integers from 1 to 50. Use the while 11 loop and modulus operator to perform the task. Total 30 Marks

Page 5 of 6
Java December 2012 Final NCC Education Ltd 2012

QUESTION 13 a) Given the following declaration: String name = Suzzy int someInt = 4; Call a String method to perform each of the following tasks: i) ii) iii) iv) v) (vi) Convert the string name to lowercase. Find out the position of the character u in the string name. Find out the character at the position 1 in the string name. Find out if the string name starts with Su. Replace the character n in the string name with another y. Convert the integer someInt to a String.

Marks

2 2 2 2 2 2 2

(vii) Find the sub string of length 3 in the string name starting at the first character.

b) (i) (ii)

Explain briefly three standard dialog boxes of the JOptionPane class. Write the import statement to use the JOptionPane class to accept and display user input.

6 1

(iii) Write a statement to create an input dialog box prompting the user to enter three initials 3 and store user input in a String variable named response. (iv) Write a statement to create a message dialog box to display the users input stored in the 2 String response. Write a statement to create a confirm dialog box that asks the user to confirm that the 2 initials entered are correct. Write a statement to close the program. 2 Total 30 Marks

(v)

(vi)

END OF EXAM

Page 6 of 6
Java December 2012 Final NCC Education Ltd 2012

Você também pode gostar