Anda di halaman 1dari 4

ASSIGNMENT

JAN 2010 SEMESTER

CDOP3203 – JAVA PROGRAMMING


INSTRUCTIONS:
• Answer the TWO (2) questions below
• Marks will be deducted (or even can be given 0) if your assignment answer
contains any plagiarism or copied directly from your coursemate
• This assignment should be completed individually.

QUESTION /SOALAN 1

Define a class called Month. Your class will have one attribute of type int to
represent a month (1 for January, 2 for February, and so forth). Include all the
following methods in this class:

a) a constructor to set the month using the first three letters in the name of
the month as three arguments (‘J’ ‘A’ ‘N’ for January, ‘F’ ‘E’ ‘B’ for
February, and so forth),

b) a constructor to set the month using an integer as an argument (1 for


January, 2 for February, and so forth),
c) a default constructor,

d) an input function that reads the month as an integer,

e) an input function that reads the month as the first three letters in the
name of the month,

f) an output function that outputs the month as an integer,

g) an output function that outputs the month as the first three letters in the
name of the month,

h) and a member function that returns the next month as a value of type
Month.

Test your class in a new program which has the main() method.
[20 marks]
Takrifkan satu kelas yang bernama Month. Kelas ini akan mempunyai satu atribut
berjenis int untuk mewakili bulan (1 untuk Januari, 2 untuk Februari dan
seterusnya). Masukkan metod-metod berikut dalam kelas tersebut:

(a) suatu metod pembina untuk mensetkan bulan dengan menggunakan tiga
abjad pertama bagi suatu bulan sebagai tiga argument (‘J’ ‘A’ ‘N’ untuk
Januari, ‘F’ ‘E’ ‘B’ untuk February, dan seterusnya),

(b) suatu metod pembina untuk mensetkan bulan dengan menggunakan integer
sebagai argumen (1 untuk Januari, 2 untuk Februari dan seterusnya).

(c) Suatu metod pembina lalai

(d) Metod input yang membaca bulan dalam bentuk integer

(e) Metod input yang membaca bulan dalam bentuk tiga abjad pertama bagi nama
bulan berkenaan

(f) Metod output yang memaparkan bulan dalam bentuk integer

(g) Metod output yang memaparkan bulan dalam bentuk tiga abjad pertama bagi
nama bulan berkenaan

(h) Metod yang akan memulangkan nama bulan berikutnya sebagai nilai dalam
bentuk Month

Uji kelas anda dalam aturcara baru yang mempunyai metod main().
QUESTION/ SOALAN 2

Write a applet program to produce the following user interface. You are not
required o write codes for event handling.
[40 marks]

Tuliskan aturcara Applet untuk menghasilkan antara muka di bawah. Anda tidak
diperlukan untuk menulis kod untuk pengendalian peristiwa.

Overall total marks= 20+40=60 ---> 30%


ASSIGNMENT QUESTION ENDS HERE

Anda mungkin juga menyukai