Você está na página 1de 11

CONFIDENTIAL

CS/JAN 2012/CSC435

UNIVERSITI TEKNOLOGI MARA FINAL EXAMINATION

COURSE COURSE CODE EXAMINATION TIME

OBJECT ORIENTED PROGRAMMING CSC435 JANUARI2012 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) ii) iii) the Question Paper an Answer Booklet - provided by the Faculty an Objective Answer Sheet - provided by the Faculty

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


This examination paper consists of 11 printed pages
Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

CONFIDENTIAL PART A (30 MARKS)

CS/JAN 2012/CSC435

1. What is the value of a after the following code fragment? String sentence; i n t a; sentence = "Excellent student"; a = sentence.indexOf("excel" ) ;

A. B. C. D.

-1 0 4 Any random value

2. Given the following code fragment: i n t [] ABC = new i n t ABC [4] ; ABC[0] = 1 0 ; f o r ( i n t i = 1; i < 4 ; i++) { ABC[i] } What is the value of ABC [3 ] ? A. B. C. D. 20 15 25 30 = ABC[i-l] + 5;

3. What is the difference between a Java applet and a Java application? A. B. C. D. An applet runs in browser's window or Applet Viewer An application execution starts with the main method An applet is called from within another application All of the above method must be called using the "new"

4. Unlike other methods of an object the keyword. A. B. C. D. constructor mutator processor retriever

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL 5. Consider the following statements. public class Rectangle

CS/JAN 2012/CSC435

{
private double length, width, area, perimeter; public void setLengthWidth(double 1, double w ) ; public void calculatePerimeter(); { } public string toStringO; { } { }

}
public class RectangleApp

{
public static void main(String[] args)

{
R e c t a n g l e Rect0 07;
} } Which of the following statements is NOT correct? A. Rect007. calculatePerimeter() ; B. Rect007 = new RectangleData() ; C. Rect007.setLengthWidth() ; D. Cout << Rect007.toString() ; 6. A method of a class that is used to return the value of a private field. A. B. C. D. constructor mutator processor accessor

7. What is the meaning of " t h i s " keyword? A. B. C. D. A Boolean expression An access modifier A variable A self-referencing pointer

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/JAN 2012/CSC435

8. Given the following diagram to show the inheritance structures of PosMaiaysia, PosEkspress and PosLaju classes: PosMaiaysia

PosEkspress

PosLaju

Which of the following code will be the normal constructor of PosLaju class? A. p u b l i c PosLaju super () ; (...)

B. p u b l i c PosLaju

(]

super

() ; (

C. p u b l i c PosLaju

super(..);

D. p u b l i c S e t d a t a P o s L a j u

(...)

9. The following key words are normally found in the inheritance and polymorphism concepts EXCEPT A. instanceof B. abstract C. extends D. override

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/JAN 2012/CSC435

10. Which of the following statements are the benefits of polymorphism? I. It makes possible smooth and easy extension of a program II. It enables the program to store different objects in different arrays. III. It enables the program to store different objects in a single array. IV. It makes the program easy to write but difficult to modify. A. I , III B. I, I I , III
C . II, III, I V

D. All of the above 11. If a class is declared as a b s t r a c t , which of the following statements CORRECT? A. B. C. D. The class cannot be instantiated. Abstract method is not allowed for this class. A subclass cannot be created from this class. An array of this class cannot be created .

12. The F i l e class enables you to A. B. C. D. open a file close a file determine a file's size all of the above

13. Which of the following package contains all the classes use in file processing? A. B. C. D. java.lang java. file java.io java.process

14. The statement F i l e


A. B. C. D.

aFile

= new File

("myFile.txt"); creates a file

on the disk in drive A on the desktop directory on the default disk drive on the temp folder on drive C the file.

15. Before a program can use a data file, the program must A. B. C. D. open create store close

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/JAN 2012/CSC435

PART B (70 MARKS)

QUESTION 1 Trace and show the output for the following program segment? int ARRAYSIZE = 6; int [] ary = new int[ARRAYSIZE]; ary[0] = 27 ary[l] = 9; ary[2] = 18 ary [3] = 63 ary [4] = 4 0 ary[5] = 8 8 for(int i = 0; i <= 3; i++)

{
if(ary [i] < ary [i + 1])

{
ary[i+2] = ary[i] - 1;

}
else ary[i+2] = i;

}
for(int i = 0; i < ARRAYSIZE; i++)

{ }

System.out.printIn("ary["+ i + "] = "+ ary[i] ) ; (5 marks)

QUESTION 2 ZelPhone is a broadband service provider. Assume that ZelPhone class for billing consists of the following data members (attributes). Define the complete ZelPhone class definition with following attributes: . Account number (eg: A1236,) Package (e.g: BB110, BB150, BB200) Bill date (in DDMMYY format, eg 150711) Current Charges (float) Outstanding Amount (float) (4 marks) Complete the ZelPhone class above with the following methods: a) Normal constructor that set all data with values given through the parameter. (2 marks) b) A Mutator method. (2 marks)
Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

CONFIDENTIAL

CS/JAN 2012/CSC435

c) Retriever methods for Account number, Package, Amount

Current Charges, Outstanding

(4 marks) d) A method to identify packages and return the discount rate. The discount can be determine through the package subscribed as shown below: -Pa^sige^, - ^ O f c c o i S H ^ :-*'* BB110 10% BB150 20% BB200 35% (2 marks) e) A processor method to calculate the total amount for the bill. The total amount for the bill is calculated as follow: Discount = Current Charges x Discount rate Total amount = Current Charges + Outstanding Amount - Discount (3 marks) f) A printer method to display the bill. (3 marks) QUESTION 3 Given the following Biz20 and Biz5 subclasses are inherited from u n i f i superclass. Superclass: U n i f i Attributes: String customerName; String customerIC; String date;

//customer name //customer IC //date of register

Subclass: Biz20 Attributes:


/*customer must choose the plan either 'home' or 'business'. The details are shown in the table below.*/ boolean govServ; /*customer either government servant or not. If the customer is government servant discount will be given from the total of payment. Formula: total of payment =(installation + monthly) discount */ Plan Home Business Installation fee (RM) 90.00 110.00 Monthly fee (RM) 68.00 148.00 Government discount 10% 15% String plan;

Table 3.1 :Details of Biz20 information.


Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL Subclass: Biz5 Attributes: String ipAddress; boolean familyPlan; boolean studentPlan; final double familyFee = 58.00, final double studenFee = 38.00;

CS/JAN 2012/CSC435

//dynamic IP address //either yes or no //either yes or no // monthly "family fee // monthly student fee

a) Write the normal constructor methods for superclass and both subclasses (6 marks) b) The accessor methods for each attribute from both subclasses (exclude the constant variables) (3 marks) c) Write the processor method for subclass Biz20 which return the total payment of Biz20 U n i f i plans. (2 marks) QUESTION 4 Given the following Bahulu and KekLapis subclasses which are inherited from rayaCookieShoppe superclass. Superclass: rayaCookieShoppe Attributes: String custOrderNo char typeOfOrder

// customer order number // 'I1 - through internet, discount 10' // 'P' - phone called

// method to calculate the //charges public String getOrderNoO // retriever for customer order number public char getTypeOrder() // retriever for type of order public void toStringO // display data Subclass: Tart Attributes:

Methods: public abstract

double

calChargesO

int qty
char j emFlavour

// pieces of cookies; order in multiple 50 // 'P1 - Pineapple, 'B' - Blueberry

Details of charges are shown in the table below: Flavour Pineapple Pineapple Blueberry Blueberry
Hak Cipta Universiti Teknologi MARA

Quantity 50 >50 50 >50

Price per jar (of 50 pieces) RM35.00 RM27.50 RM40.00 RM35.50 CONFIDENTIAL

CONFIDENTIAL

CS/JAN 2012/CSC435

Methods: public double calChargesO public int getQtyO public char getFlavour() public void toStringO Subclass: Kerepek Attributes: char type float weight boolean giftWrap into raya gift box. Methods: p u b l i c double c a l C h a r g e s O public float getWeight0 p u b l i c boolean g e t W r a p 0 public void t o S t r i n g O

// method to calculate the charges // retriever for qty // retriever for flavour // display data

// // // //

'P' - kerepek pisang 'U1 - kerepek ubi weight of the kerepek, e.g. 2 kg true or false to pack the kerepek

// // // //

method t o c a l c u l a t e t h e r e t r i e v e r f o r weight r e t i r e v e r f o r giftWrap display data

charges

The charge for the "kerepek" is based on the weight and gift wrap service, RM10.50 per kg and RM15.00 for gift wrap service. Do the following tasks. DO NOT write a complete program. a) Write the methods c a i c h a r g e s () to calculate the total charges for both subclasses. (8 marks) b) Given the following: rayaCookieShoppe[ ] T = new rayaCookieShoppe [25] ; i) Write a program segment to determine and display the number of customers who order "Tart" and "Kerepek" made by rayaCookieShoppe. (4 marks) Write a program segment to calculate the total charges for all customers which made an order through the rayaCookieShoppe website. (4 marks) Assuming that all classes have toStringO methods, write a program segment to search and display the detailed information for all "BlueberryTart" customers. (3 marks)

ii)

iii)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

10

CS/JAN 2012/CSC435

QUESTION 5 Adib Sports Center would like to keep track the records of all athlete who won the medal for overall events involved in the year 2011. You are given a file named s p o r t . t x t that contains name of athlete, category of event, number of gold medal, number of silver medal and number of bronze medal as shown below: WH^fKK^^^^F^-c'

^ ^ ^ ^ ^ ^ ^ ^ S w S : ;?

;;:;.,..:.;..

'

,. .

^apfB^Bip^iipiSPiSIp

.jkSS^^s^^^^mmM
j * .

File Edit Format View Hetp = A"ii b i n Hassan; P r o f e s s i o n a l ; 12; 2; 7 Adib b i n A b u ; A m a t u r ; Q ; 1 2 ; i l | H a s i f b i n Amiraiddin; Amatur; 18; 2; 3 Badaruddin Am b i n A m r a n ; P r o f e s s i o n a l ; 1 1 ; 3 ; 0 Muhamad w a i d i b i n N g a j a ; P r o f e s s i o n a l ; 3;23; 11 Mohd z a k i b i n s a d r i ; P r o f e s s i o n a l ; 1 ; 0 ; 2 3 Hashim b i n Yahuzah;Semi Amatur; 1 1 ; G; Q Saileh bin selamat;Amatur;7;8;9 KHairul Amrin b i n Abdul M a j i d ; P r o f e s s i o n a l ; 2 0 ; 3 ; 2 Ahmad Naqib b i n Ahmad N a u f a l ; A m a t u r ; 1 ; 1 1 ; 1 0

|
i

1
^

A sample of S p o r t . t x t file Write a complete program to perform the following: a) b) Read all records from the file named S p o r t . t x t . Calculate the total medal (gold, silver and bronze) won by each athlete and p o i n t that would be given based on category of event. If the category of event is P r o f e s s i o n a l , then the point is 10, else the point given is 5. Then multiply the point by total medal in order to get the total point. Determine and display the best athlete in the year 2011 based on the highest total point on the screen. Write the following to the file named P r o f e s s i o n a l . t x t : i) ii) e) Information of all records for athlete involved in professional event. Summarize the total number of athlete involved and their overall total point.

c)

d)

Write the following to the file named AmaturElse. t x t : i) Information of all records for athlete involved in another event. ii) Summarize the total number of athlete involved and their overall total point. Use exception handling operations to deal with input-output errors

f)

The expected output of the program as shown below:

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

11

CS/JAN 2012/CSC435

^WBaM^^^^^^^^^^MBH^
Options The b e s t a t h l e t e i s Muhamad Wajdi b i n Hgaja I The t o t a l score p o i n t i s 370 < I ,.,.. .. . , . . , , . . _ ,_ __-Jft .., .-.,--...-> ^-^i
r-

8 'a I

|| A 11

Sample output of terminal window.

!)" nn;J: d * , . J '

:. RECORD FOR PROFESSIONAL ATHLETE Name category l Ali bin Hassan professional Badaruddin Am bin Amran Professional Muhamad waidi bin Ngaja Professional Professional Mohd zaki bin sadri Professional KHairul Amrin bin Abdul Majid medal 21 14 37 24 25

Total point
210 140 370 240 250

The number o f p r o f e s s i o n a l a h l e t e i s 5 The o v e r a l l t o t a l p o i n t f o r p r o f e s s i o n a l a t h l e t e i s 1210

Sample output of " P r o f e s s i o n a l . t x t " file

^^w^^^m^mm^^^^m.

lilli^^
View Help

^^^^^^^^^^^^^^^^

m :

File

Edrt

Format

RECORD FOR AMATUR ETL ATHLETE f Name Category T o t a l meda1 A d i b b i n Abu Amatur 23 H a s i f b i n A m i n u d d i n Amatur 23 Hashim b i n Yahuzah semi Amatur 11 s a i l e h b i n selamat Amatur 24 Ahmad Naqib b i n Ahead N a u f a l Amatur 22

Total

point 230 230 110 240 220

The number o f a t h l e t e f r o m o t h e r c a t e g o r y i s 5 The o v e r a l l t o t a l p o i n t f o r o t h e r c a t e g o r y o f a t h l e t e i s 1 0 3 0

Sample output of " A m a t u r E l s e . t x t " file


(15 marks)

END OF QUESTION PAPER

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

Você também pode gostar