0% found this document useful (0 votes)
37 views8 pages

Oop 1

1. This section consists of two structured questions about object oriented programming in Java. Question 1 has parts that ask about Java architecture components, advantages of OOP, identifying fields and methods from a class description, UML diagram types, Java error types, and detecting and locating errors in a code segment. Question 2 focuses on classes, objects, attributes, and methods based on various scenarios and class diagrams. 2. The document provides instructions, questions, code segments, class diagrams and scenarios for students to answer questions about object oriented programming concepts in Java. Students are asked to identify, describe, list, write programs based on the material provided. 3. The questions assess students' understanding of important OOP concepts in Java
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views8 pages

Oop 1

1. This section consists of two structured questions about object oriented programming in Java. Question 1 has parts that ask about Java architecture components, advantages of OOP, identifying fields and methods from a class description, UML diagram types, Java error types, and detecting and locating errors in a code segment. Question 2 focuses on classes, objects, attributes, and methods based on various scenarios and class diagrams. 2. The document provides instructions, questions, code segments, class diagrams and scenarios for students to answer questions about object oriented programming concepts in Java. Students are asked to identify, describe, list, write programs based on the material provided. 3. The questions assess students' understanding of important OOP concepts in Java
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

SULIT DFC3013 : OBJECT ORIENTED PROGRAMMING

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

Nyatakan EMPAT(4) komponen penting di dalam senibina Java.

[4 marks]
[4 markah]

CLO1 (b) i) Describe THREE (3) advantages of using OOP.


C2
Huraikan TIGA (3) kelebihan menggunakan OOP.

[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]

CLO1 (c) List TWO (2) types of errors in Java.


C1
Senaraikan DUA(2) jenis ralat di dalam Java.

[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.

1 public class Test


2 {
3 public static void main(String[] args)
4 {
5 int[] x = new int[9];
6 for (i = 0; i < x.length-1; i++)
7 {
8 x[i] = i;
9 system.out.println(x[i]);
10 }
11 }
12 }

Figure B2 / Rajah B2

[3 marks]
[3 markah]

18 SULIT
SULIT DFC3013 : OBJECT ORIENTED PROGRAMMING

CLO2 (e) Identify the output of the program in Figure B3.


C1
Kenalpasti ‘output’ bagi program di dalam Rajah B3.

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’.

public static void main(String args [])


{
int value=4;

for (int num=1; num <=12; num++)


{
int multiple=num * value;
System.out.println(multiple);
}
}

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

i. Identify the object name.


Kenalpasti nama objek.
[1 mark]
[1 markah]
ii. List the attribute.
‘Attribute’
[5 marks]
[5 markah]
iii. Identify the methods.
Kenalpasti metod yang terlibat.
[2 marks]
[2 markah]

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]

(c) Apply a Java program based on statement below.


CLO2
C3
Tuliskan satu program Java berdasarkan pernyataan di bawah.

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]

(d) i) Identify types of exception based on segment code below.

Kenalpasti jenis pengecualian berdasarkan kod segmen di bawah.


CLO2
C2

a) int a[ ] = new int[5];


a[10]=50;

b) int i = Integer.parseInt("abc");

c) String s = "FOOTBALL";
double d = Double.parseDouble(s);
[3 marks]
[3 markah]

CLO2 ii) Describe TWO (2) ways of creating thread.


C2
Huraikan DUA (2) kaedah untuk mencipta thread.

[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.

class FirstThread extends Thread


{
public void run()
{
int a = 8,b = 4;
System.out.println("Amount is "+(a+b));
}
}

class SecondThread extends Thread


{
public void run()
{
int c = 13,d = 5;
System.out.println("Average is "+((c+d)/2));
}
}

public class TestThread


{
public static void main(String args[])
{
System.out.println("Thread Example");
FirstThread obj1 = new FirstThread();
obj1.start();
SecondThread obj2 = new SecondThread();
obj2.start();
Figure 7 / Rajah 7
}
}

Figure B7 / Rajah B7
[3 marks]
[3 markah]

SOALAN TAMAT

23 SULIT

You might also like