You are on page 1of 8

NO MATRIK: …………………………………..

CONFIDENTIAL /SULIT

JANUARY 2020 SEMESTER/ SEMESTER JANUARI 2020


FINAL EXAMINATION/ PEPERIKSAAN AKHIR
(ESSAY/ ESEI)

COURSE/ KURSUS : JAVA PROGRAMMING

CODE / KOD : CDOP3203

DATE/ TARIKH : 23 APRIL 2020

TIME / MASA : 23 APRIL 2020 (1:00AM) – 24 APRIL 2020 (8:00AM)

INSTRUCTIONS TO CANDIDATES/ ARAHAN KEPADA CALON

1. This question paper is set in English and Bahasa Melayu. ANSWER ALL questions using
ONE LANGUAGE ONLY either ENGLISH or BAHASA MELAYU.
Kertas soalan ini disediakan dalam Bahasa Inggeris dan Bahasa Melayu. JAWAB SEMUA soalan dalam
SATU BAHASA SAHAJA sama ada BAHASA INGGERIS atau BAHASA MELAYU.

2. Read CAREFULLY the instructions for each PART.


Baca DENGAN TELITI arahan bagi setiap BAHAGIAN.

3. In the event any discrepancies, the English Version shall be used.


Sekiranya terdapat sebarang percanggahan pada soalan peperiksaan, versi Bahasa Inggeris
hendaklah diguna pakai.

4. Submit your answer ONLINE.


Hantar jawapan anda secara ONLINE.

5. Submission deadline : 24 APRIL 2020 (8:00AM)


Tarikh akhir penghantaran

This question paper consists of Part A & Part B only.


Kertas soalan ini mengandungi Bahagian A dan Bahagian B.
CDOP3203/JAN 2020/F

PART A/ BAHAGIAN A

INSTRUCTIONS/ ARAHAN

Part A contains FIVE questions. Answer ALL questions only.


Bahagian A mengandungi LIMA soalan. Jawab SEMUA.

QUESTION/ SOALAN: MARKS/ MARKAH

1. Consider the following statement:

X is an approach in which one class acquires the property of another class.


With X, we can reuse the data fields and methods from the existing class.

Identify X.
(4)
Pertimbangkan pernyataan berikut:

X adalah pendekatan yang mana suatu kelas memperolehi ciri-ciri kelas yang
lain. Dengan X, kita boleh menggunakan semula medan data dan metod
daripada kelas yang sedia ada.

Kenalpasti X.

2. Differentiate between “class” and “subclass”.


(4)
Bezakan antara “kelas” dan “subkelas”.

3. An attribute of a class has been declared as private with data type integer.
How would you access the value of this attribute from a different class?
(4)
Suatu atribut kelas telah diisytiharkan sebagai private dengan data berjenis
integer. Bagaimanakah anda akan mengakses nilai atribut ini daripada kelas
yang lain?

1
CDOP3203/JAN 2020/F

4. What is the value of the attribute y after a second object of type A being
created?

(4)

Apakah nilai bagi atribut y selepas objek kedua daripada jenis A diwujudkan?

class A {

static int y=1;

public A () {
y=y+3;
}

5. Explain briefly what is “method overriding”.


(4)
Jelaskan secara ringkas apakah itu “pembatalan metod”.

(Total/ Jumlah: 20)

2
CDOP3203/JAN 2020/F

PART B/ BAHAGIAN B

INSTRUCTIONS/ ARAHAN

Part B contains THREE questions. Answer TWO only.


Bahagian B mengandungi TIGA soalan. Jawab DUA sahaja.

QUESTION/ SOALAN: MARKS/ MARKAH

1. Write a class definition to model a bank account. The information of this


class is given below:

Class name: Account

Attributes:

private int id
private double balance

Methods:

Constructor
Purpose: It has two parameters which have values to be assigned
respectively to all
the attributes of this class

public int getId ()


Purpose: To return the value of the attribute id

public double getBalance ()


Purpose: To return the value of the attribute balance

public void setId (int id)


Purpose: To assign new value for id

public void withdraw (double amount)


Purpose: To withdraw cash. In this method, the value of attribute balance
will be
updated based on the amount withdrawn. The parameter of this method
represents
the amount that need to be withdrawn. Assume that the balance would not
be
negative.

public void deposit (double amount)


Purpose: To enter deposit. In this method, the value of attribute balance
will be
updated based on the amount deposited. The parameter of this method

3
CDOP3203/JAN 2020/F

represents
the amount that need to be deposited

(Total/ Jumlah: 20)

Tuliskan satu definisi kelas untuk memodelkan suatu akaun bank. Maklumat
berkenaan kelas ini diberikan di bawah:

Nama Kelas: Akaun

Atribut:

private int id
private double baki

Metod:

Metod Pembina
Tujuan: Metod ini mempunyai dua parameter yang mana nilainya akan
diumpukkan
masing-masing kepada semua atribut yang ada di dalam kelas ini

public int getId ()


Tujuan: Untuk memulangkan nilai atribut id

public double getBalance ()


Tujuan: Untuk memulangkan nilai atribut baki

public void setId (int id)


Tujuan: Untuk mensetkan nilai id yang baru

public void withdraw (double amount)


Tujuan: Untuk mengeluarkan duit. Dalam metod ini, nilai baki akan
dikemaskini mengikut
jumlah yang dikeluarkan. Parameter di dalam metod ini mewakili nilai yang
perlu
dikeluarkan. Andaikan baki tidak akan menjadi negatif.

public void deposit (double amount)


Tujuan: Untuk memasukkan deposit. Dalam metod ini, nilai baki akan
dikemaskini mengikut
jumlah yang didepositkan. Parameter di dalam metod ini mewakili nilai yang
perlu
didepositkan

4
CDOP3203/JAN 2020/F

2. Create a class named Person and its two subclasses named Student and
Employee.

A Person has a name, address, phone number and email address as private
attributes. In addition, it also has a constructor, accessor and mutator
methods for all the attributes. This class also has a display() method in
order to display the value of the attributes.

A Student has a student number as a private attribute. In addition, it also


has a constructor, accessor and mutator methods for the attribute. This
class also has a display() method in order to display the value of the
attributes including those from the superclass.

An Employee has salary and department id as its private attributes. In


addition, it also has a constructor, accessor and mutator methods for all the
attributes. This class also has a display() method in order to display the
value of the attributes including those from the superclass.

Note: Override the display() method in each class to display the value of the
attributes in the both superclass and the subclass.

(Total/ Jumlah: 20)

5
CDOP3203/JAN 2020/F

Hasilkan satu kelas dengan nama Person dan dua subkelasnya bernama Student
dan Employee.

Seorang Person mempunyai nama, alamat, nombor telefon dan alamat email
sebagai atribut private. Sebagai tambahan, ia juga mempunyai metod pembina,
metod-metod accessor dan mutator bagi semua atribut. Kelas ini juga
mempunyai metod display() bagi memaparkan nilai-nilai atribut.

Seorang Student mempunyai nombor pelajar sebagai atribut private. Sebagai


tambahan, ia juga mempunyai metod pembina, metod-metod accessor dan
mutator bagi atribut. Kelas ini juga mempunyai metod display() bagi
memaparkan nilai atribut termasuk atribut daripada superkelas.

Seorang Employee mempunyai gaji and ID jabatan sebagai atribut private.


Sebagai tambahan, ia juga mempunyai metod pembina, metod-metod accessor
dan mutator bagi semua atribut. Kelas ini juga mempunyai metod display() bagi
memaparkan nilai-nilai atribut termasuk atribut daripada superkelas.

Nota: Batalkan metod display() bagi setiap kelas untuk memaparkan nilai
atribut bagi kedua-dua superkelas dan subkelas.

6
CDOP3203/JAN 2020/F

3. Write an Applet program to produce the following user interface. You are
not required to write the codes for the event handling.

(Total/ Jumlah: 20)

Tuliskan aturcara Applet untuk menghasilkan antara muka seperti berikut. Anda
tidak diperlukan untuk menulis kod bagi pengendalian peristiwa.

END OF QUESTION PAPER / KERTAS SOALAN TAMAT

You might also like