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),
e) an input function that reads the month as the first three letters in the
name of the month,
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).
(e) Metod input yang membaca bulan dalam bentuk tiga abjad pertama bagi nama
bulan berkenaan
(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.