Oop 1
Oop 1
SECTION B : 55 MARKS
BAHAGIAN B : 55 MARKAH
INSTRUCTION:
This section consists of TWO (2) structured questions. Answer ALL questions.
ARAHAN:
Bahagian ini mengandungi DUA (2) soalan berstruktur. Jawab semua soalan.
QUESTION 1 / SOALAN 1
CLO1
(a) States FOUR(4) important components in Java architecture.
C1
[4 marks]
[4 markah]
[3 marks]
[3 markah]
16 SULIT
SULIT DFC3013 : OBJECT ORIENTED PROGRAMMING
CLO1 ii) Identify the fields and methods based on the statement given in Figure B1.
C2
Kenalpasti ciri-ciri dan kaedah berdasarkan pernyataan yang diberikan di
dalam Rajah B1.
Each bicycle was built from the same set of blueprints. Therefore, it
contains the same components like brake and speed. It moves when
speed increases and stops when brake is applied.
Setiap basikal dibina dari set pelan induk yang sama. Oleh sebab itu,
ia mengandungi komponen yang sama seperti brek dan kelajuan. Ia
bergerak apabila kelajuan meningkat dan berhenti menggunakan
brek.
Figure B1 / Rajah B1
[2 marks]
[2 markah]
CLO1 iii) UML can be used as a sketch. Identify and explain TWO (2) types of design to
C2 sketch the UML.
UML boleh digunakan sebagai lakaran. Kenal pasti dan jelaskan DUA (2) jenis
reka bentuk bagi melakar UML.
[2 marks]
[2 markah]
[2 marks]
[2 markah]
17 SULIT
SULIT DFC3013 : OBJECT ORIENTED PROGRAMMING
CLO1 (d) A code segment below have TWO (2) errors. Detect the errors based on Figure B2
C2 and write the line number where the errors occurred.
Keratan kod di Rajah B2 mempunyai DUA (2) ralat. Kenalpasti ralat tersebut
dan tuliskan nombor baris di mana ralat tersebut berlaku.
Figure B2 / Rajah B2
[3 marks]
[3 markah]
18 SULIT
SULIT DFC3013 : OBJECT ORIENTED PROGRAMMING
int x = 7;
switch (x)
{
case 8: System.out.print(“DFC3013”);
case 7: System.out.print(“ OBJECT”);
case 6: System.out.print(“ ORIENTED”);
case 9: System.out.print(“ PROGRAMMING”);
default: System.out.print(“ wrong input!!”);
}
Figure B3 / Rajah B3
[2 marks]
[2 markah]
CLO2 (f) Refer to the segment code in Figure B4, convert the code into the do while loop.
C3
Berdasarkan kepada keratan kod di dalam Rajah B4, tukarkan kod tersebut ke gelung
‘do while’.
Figure B4 / Rajah B4
[7 marks]
[7 markah]
19 SULIT
SULIT DFC3013 : OBJECT ORIENTED PROGRAMMING
QUESTION 2 / SOALAN 2
CLO2 (a) Answer the questions below based on given situation in Figure B5.
C1
Jawab soalan di bawah berdasarkan situasi yang diberikan di dalam Rajah B5.
Klinik Fatihah Dungun is one of the new clinic launch on January 2015. Once
patient have been registered, their information will be recorded such as ic
number, name of patient, address, date and disease. The appropriate medicine
will be given to the patient depending on the disease and the staff will print
the patient detail for documenting.
Figure B5 / Rajah B5
20 SULIT
SULIT DFC3013 : OBJECT ORIENTED PROGRAMMING
CLO2 (b) Based on the UML class diagram in Figure B6, write a program to declare the class,
C2 fields, methods and create a main method to execute the program.
Berdasarkan rajah kelas UML di dalam Rajah B6, tuliskan program untuk
mengisytiharkan kelas, pembolehubah, kaedah dan mencipta kaedah utama untuk
melaksanakan program.
Student
─ Name : String
+ DisplayName( ) : void
Figure B6 / Rajah B6
[8 marks]
[8 markah]
i) Create Animal class and Cat class. Cat class is a sub class, meanwhile Animal
class is a super class.
Cipta kelas Animal dan kelas Cat. Kelas Cat adalah kelas sub, manakala kelas
Animal adalah kelas super.
[2 marks]
[2 markah]
ii) Create a default constructor in the Cat class to invoke the default constructor
of the super class.
Cipta ‘default constructor’ dalam kelas Cat untuk memanggil ‘default
constructor’ bagi kelas super.
[2 marks]
[2 markah]
21 SULIT
SULIT DFC3013 : OBJECT ORIENTED PROGRAMMING
iii) Create a main method in Cat class and create an object named jepp inside the
main method of Cat class.
Bina ‘main method’ di dalam kelas Cat dan bina satu objek bernama jepp di
dalam ‘main method’ kelas Cat.
[2 marks]
[2 markah]
b) int i = Integer.parseInt("abc");
c) String s = "FOOTBALL";
double d = Double.parseDouble(s);
[3 marks]
[3 markah]
[2 marks]
[2 markah]
22 SULIT
SULIT DFC3013 : OBJECT ORIENTED PROGRAMMING
(e) Illustrate the output for the program code in Figure B7.
CLO2
C3
Tafsirkan ‘output’ yang terhasil untuk kod program di dalam Rajah B7.
Figure B7 / Rajah B7
[3 marks]
[3 markah]
SOALAN TAMAT
23 SULIT