Anda di halaman 1dari 10

CONFIDENTIAL CS/OCT 2009/CSC238/435

UNIVERSITI TEKNOLOGI MARA


FINAL EXAMINATION

COURSE OBJECT-ORIENTED PROGRAMMING


COURSE CODE CSC238/435
EXAMINATION OCTOBER 2009
TIME 3 HOURS

INSTRUCTIONS TO CANDIDATES

1. This question paper consists of two (2) parts : PART A (15 Questions)

PART B (5 Questions)

2. Answer ALL questions from all two (2) parts :

i) Answer PART A in the Objective Answer Sheet.


ii) Answer PART B in the Answer Booklet. Start each answer on a new page.
3. Do not bring any material into the examination room unless permission is given by the
invigilator.

4. Please check to make sure that this examination pack consists of:

i) the Question Paper


ii) an Objective Answer Sheet - provided by the Faculty
iii) an Answer Booklet - provided by the Faculty

DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO


This examination paper consists of 10 printed pages
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
CONFIDENTIAL 2 CS/OCT 2009/CSC238/435

Answer ALL Questions

PART A (30 marks)

1. Which of the following statements is TRUE?

A. Polymorphism and inheritance is essentially the same thing.


B. Polymorphism means that the method executed in response to a given message will
vary according to the class to which the object belongs.
C. The instance of operator tests whether an object exist.
D. Polymorphism uses array of subclasses.

2. The following statements are true, EXCEPT:

A. Subclasses can access their parents' protected member variables.


B. The super () calls the superclass of the calling method's constructor.
C. A Java interface declares a set of methods with no implementation.
D. A class can call its subclass private methods.

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

4. With text I/O, .

A. data are read and saved as strings


B. data are read and saved as objects
C. data are read and saved as byte
D. all of the above.

5. Which of the following is a method that might throw a NumberFormatException?

A. Double.parseDouble
B. String.concat
C. Math.min
D. System.out.println

6. Accessor methods are used to .

A. initialize objects
B. retrieve the value of data members
C. perform calculations
D. assign values to data members of a class

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 3 CS/OCT 2009/CSC238/435

7. Retriever methods are used

A. to assign values to data members of a class


B. to get the values of attributes
C. to perform calculation
D. to initialize object

8. Which of the following statements is an advantage of polymorphism?

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

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 4 CS/OCT 2009/CSC238/435

Questions number 10 and 11 are based on the following program segment:

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

11. What is the output when statement B is executed?

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

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 5 CS/OCT 2009/CSC238/435

13. Given the following Java program segment.

publ ic static void main (String[] args)


{
Person lect = new Person; - ->statement I
Person[] stud = new Person[40]; — > statement II
Vehicle bus = new Vehicle C Abu Baka r",8, 0);
—>statement III
//read data

lect.setvalue (name, dept, carNumber) ; — > statement IV

}//end main

Which of the following statements are TRUE?

I. THREE objects were declared in the above program


II. s t a t e m e n t i n will execute a default constructor of class V e h i c l e
III. s t a t e m e n t i v will execute a mutator method of class Person
IV. array s t u d can hold 39 objects only

A. I and III only


B. II and IV only
C. II, III and IV only
D. I and IV only

14. Which of the following declares an array of s t u d e n t objects of size 20?

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

A. Objects can have objects as their data members.


B. Classes can have objects as their data members.
C. Objects declared in the main program can only access public members of a class.
D. Each class could contain data members and a set of methods that can manipulate
the data members.

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 6 CS/OCT 2009/CSC238/435

PART B (70 marks)

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)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 7 CS/OCT 2009/CSC238/435

QUESTION 3

Given the following definition

public abstr<act class Student


s
i
private String name ;
private double testa-
private double tes t2;
private double test3;
protect ed char grade;

public Student(String n, double tl, double t2, double t3)


{ . .• i
public abstract char computeGrade() ;

// 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)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 8 CS/OCT 2009/CSC238/435

QUESTION 4

Given the following inheritance hierarchy

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

Subclass : class WaterPark

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

Subclass : class WildlifePark

Data member(s):
String category; // category of the customers

Methods:
String getCategory();// return the category
double calCharges();// calculate the charges

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 9 CS/OCT 2009/CSC238/435

a) Write the normal constructors for superclass and both subclasses.


(6 marks)

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

Write abstract methods named c a l c h a r g e s () to calculate the charges of the activities


for both WaterPark and w i i d i i f e P a r k classes. The customers who are the members
of the theme park will be given a special discount of 25% for every total charges.

(9 marks)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 10 CS/OCT 2009/CSC238/435

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.

File Edit Format View Help


.2002200202;ALI BAKAR;CS110;1;CSC1Q0;C5C102;CSC103;BELlOO; XMK100
12002200221;RAMLI SAMAD;CSlli;1;CSC100;CSC102;CSC1Q3; BELlOO; IMK100
12002200203;MXNAH BAKRI;CS110;2;CSClOQ;CSC102;CSC103; BELlOO; IMK100
i 2002200204;JUSOH AWANG;C5110;2;CSC100;CSC102;C5C103; BEL101; IMK100
12002200205;ASRI MURAD;CS111;1:CSC10Q;CSC102:CSC104;BELlOO; IMK100
200220Q206;3.AMILAH AWANG;cslli;!;csclOO;csci02;CSC104;BELlOO; IMK100
2002:200207; SURI MURAD: CS110; 1;CSC100;CSC102; CSC104; BELlOO; IMK100
2002200208;AHMAD ALBAB;CS110;1;CSC100;CSC102;CSC104;BELlOO; IMKlOO
2002200209;JAMIL MIRDAD;CS112:2;CSC100; CSC102;CSC105;BELlOO;IMK100
2002200210;SAMAD AHMAD;CS112;i;CSC100;CSC102;C5C105; BELlOO: IMK100

Write a complete Java program based on the following requirements:


• Reads the data from the file and filter the data into two new output text files called
cs 110. t x t and cs 1 1 1 . t x t respectively.

• 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)

END OF QUESTION PAPER

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

Anda mungkin juga menyukai