$30
CSIT121
Object Oriented Design and Programming
Assignment 3
File name MUST BE
YourName_XXX_A3.java
XXX – your class list no
Objectives:
Practice java programming with GUI, Collections.
Task 1: (5 marks)
2
What is this? You probably have seen the above scenario in the TV show or
in some of the lucky draw activities. The picture looks like some
pigeonholes; and some interesting things are hidden behind the pigeonholes;
in GUI term, we call these pigeonholes buttons. And the buttons are
initialized to some images (feel free to choose your preferable image(s)).
You can let all the buttons all have the same image to start with or different
images.
Most of the times, we get some VIP’s to open some of the pigeonholes. The
ones who own the called numbers probably win some prizes.
You are asked to design this application for someone who would like to
adopt this idea for lucky draw. In the above diagram, each button stores a
distinct integer value, for example, from 1 to 49, since we have 7 rows and 7
columns. Feel free to change to other size, but must be at least 6 rows and 6
columns; preferable to be a square of n x n so that n lucky numbers will
be drawn.
You should not assume that button 1 stores number 1, button 2 stores
number 2 and etc. A bit too easy, if you do so!!! You should actually
randomly shuffle all the 49 numbers and store them inside the buttons.
On the party or the lucky draw day, you should randomly generate the n
lucky buttons and highlight the eight numbers drawn. You can choose
probably the 1st number or the last number generated to be the top prize. Try
to have some background or foreground colors to distinguish them; and the
fonts look “bigger” for the winning numbers.
The following shows the final outcome when anyone of the buttons is
“pressed”: (The winning numbers are highlighted in blue, and top prize is
number 22)
3
For your design, use GridLayout to arrange for the layout of the GUI
components, explore the following features in your design:
- array of JButton / JTextField / Icon / ImageIcon etc
- The use of List, Arrays etc collections
Task 2: (1 mark)
You can store the winning numbers in an array and “sort” them; Of course, I
do no expect you to implement the sorting method. You are working on
functional programming; Uncle Lambda can help you to achieve this target.
If you have done Task 1 and Task 2, the following panel will be displayed
too:
4
Note that “Congratulations” is an animated image file, [1, 15, 26, 31, 43, 46]
is a List object and displayed it as String object.
IMPORTANT
Put all your classes in a file called YourName_XXX_A3.java and make
sure that this file can be compiled and can be executed. Upload ONLY this
file to Moodle. ALL ZIP FILE SUBMITTED
WILL BE REJECTED.
No re-submission will be allowed after grading.
In the above file, remember to put down your name and also the following
declaration (some similar contents):
// Tell me if it is your own work, and whether you have passed your
// program to your friends etc etc etc
// and willing to accept whatever penalty given to you.
- Wrong file name: -0.5 mark
- No declaration, no name etc: -0.5 mark
- Failing to demo: -1 marks
- Late penalty: – 0.1 per hour