INSTRUCTIONS TO CANDIDATES
1. This question paper consists of two (2) parts : PART A (15 Questions)
PART B (5 Questions)
4. Please check to make sure that this examination pack consists of:
3. What are the two standard Java packages that implement GUI-based programs?
A. j a v a . g r a p h i c s and j a v a . i o
B. j a v a x . s w i n g and j a v a . a w t
C. j a v a . g u i and j a v a g r a p h i c s
D. j a v a . u t i l and j a v a sys
A. Double.parseDouble
B. String.concat
C. Math.min
D. System.out.println
A. initialize objects
B. retrieve the value of data members
C. perform calculations
D. assign values to data members of a class
A. The same program logic can be used with objects of several related classes.
B. Variables can be re-used in order to save memory.
C. Constructing new objects from old objects of a similar class saves time.
D. Polymorphism is a dangerous aspect of inheritance and should be avoided.
9. In the following pair of classes, identify the CORRECT superclass and the subclass.
1. Publication, Book
II. Bus, Aeroplane
III. Animal, Cat
IV. Lecturer, Student
A. II, IV
B. 1, III
C. III, IV
D. III
class Hello
{
public static void main(String[] args)
{
String strl = "Hello";
String str2 = "World!";
System.out.println((strl + "Java!").charAt(5));//A
System.out.printIn(strl.substring(1,3)+
str2.substring(0,2)); //B
}
J
10. Assume the program compiles successfully and is run. What is the output when
statement A is executed?
A. o
B. J
C. l
D. a
A. elWo
B. HeWo
C. HeWor
D. elWor
12. The practice of hiding the details from the user of what goes on inside of an object is
known as .
A. polymorphism
B. inheritance
C. encapsulation
D. access modification
}//end main
A. S t r i n g s t u d e n t = new S t u d e n t ( 2 0 ) ;
B. Student s t u d e n t = new S t u d e n t [ 2 0 ] ;
C. S t u d e n t [ ] s t u d e n t = new S t u d e n t [ 2 0 ] ;
D. S t u d e n t [ 2 0 ] s t u d e n t = new S t u d e n t [ ] ;
15. Each of the following statements is TRUE about classes and objects EXCEPT
QUESTION 1
The UiTM Shah Alam Campus Clinic wants to automate the process of storing patients'
information and the billing system. You have been given the task to design the system. The
clinic normally stores information such as the patient's physical characteristics and medical
data such as blood type, blood pressure and glucose level. It also keeps a history of the
serious disease and medical operations that the patient has undergone. The clinic bill is
based on the consultation hours and the type of medication given. As the first step in the
design process, identify the objects and their attributes for the system. (DO NOT write a
class for this problem)
(5 marks)
QUESTION 2
Write the following overloaded methods definition using Java for each of the following:
i) l i s t o f N u m b e r s () - Calculate and return the sum of all numbers that are greater
than 5 of an array of floating point values. The array is passed to the function as a
parameter.
(5 marks)
ii) l i s t o f Numbers () - this function receives an array of integer and its size as
parameters. Compute and return the average of all numbers in the array.
(5 marks)
QUESTION 3
// Accessors
public String getName() {. •}
public double getTestl() { ..}
public double getTest2() { • •}
public double getTest3() { ..}
public char ge tGrade () { . .
}
public String toString (){ • •}
}
Suppose class Undergraduate and Graduate extends s t u d e n t , with no additional
attributes. Using polymorphism, write a Java application to
a) get the number of students and necessary data from the user. Store these data into an
array of students
(10 mark)
b) calculate and display the total number of students who get grade A and count how many
Of these Students from each subclass, U n d e r g r a d u a t e and G r a d u a t e .
(6 mark)
c) Find and display the information of student whose name is given by the user
(4 mark)
QUESTION 4
ThemePark
WaterPark WildlifePark
and the list of data members and methods for ThemePark, WaterPark, and WildlifePark
classes:
Superclass : a b s t r a c t c l a s s ThemePark
Data member(s):
String name; // customer's name
String icNo; // customer's identification card number
boolean member; // either member or not member of the park
Methods:
ThemePark();
ThemePark(String name, String icNo, boolean member);
String getName(); // return the customer's name
String getlc(); // return the ic number
boolean getMember (); // return the membership
String toStringO; // return the details of objects
abstract double calCharges(); // calculate the charges
Data member(s):
boolean surfBeach; // either true or false to surf
boolean waterRides; // either true or false to ride
Methods:
boolean getSurf();// return the surfing status
boolean getRide();// return the riding status
double calCharges ();// calculate the charges
String toString();// return the details of objects
Data member(s):
String category; // category of the customers
Methods:
String getCategory();// return the category
double calCharges();// calculate the charges
b) Given the details of ticket charges in table 4.1 and table 4.2 for both Water and Wildlife
Parks below:
Activity Cost(RM)
Surf Beach 25.00
Water Rides 20.00
Table 4.1 Details of ticket charges for Water Park
Category Cost(RM)
Adult 35.00
Child 20.00
Table 4.2 Details of ticket charges for Wildlife Park
(9 marks)
QUESTION 5
Given the following C o u r s e L i s t . t x t input file that contains the student number, name,
program, part, first course code, second course code, third course code, forth course code
and fifth course code. Assume each student is required to register 5 courses in a semester.
• Create another output text file called CS110BEL100.txt that contains the list of CS110
students who register for BEL100.
Use exception handling operations to deal with the file input-output errors.
(20 marks)