Quiz Programming 3

advertisement
Name : .....................................................................
Comp 240 Quiz Programming 3
ID # : .....................................................................
May 05, 2005
1/2
State clearly all of your assumptions.
You will NOT receive any partial credit if your code
does not compile correctly.
Q1 (70)
Q2 (30)
Sum
Good luck.
Q1. (70 pt)
Create a class called “Coupon” that helps its user to play the game “sayısal loto.”
The rule of the game is well known. The player has to choose numbers between 1 and 49, inclusive. The
player tries to guess with his choice those six numbers that will be announced later. According to the
number of correct choices, the player will share the total amount with other players.
Using the Coupon class, the user will be able to prepare a list of choices from the list of integers ranging
from 1 to 49.
1.a.
(10 pt)
The coupon should at least hold a list of choices, and could be able to decide
which one is selected, and which are not selected. Create the necessary instance
field(s) for this.
1.b.
(10 pt)
The class should have a constructor that takes integer numbers as parameters,
when they are ranging from 1 to 49, then the corresponding choice is marked as
selected. Here, it is important that the number of choices is unspecified.
The no-argument constructor should create an empty coupon where none of the
choices is selected.
1.c.
(10 pt)
Provide a method toString that returns a comma separated list of selected
numbers (see sample output).
1.d.
(15 pt)
Provide a method named print that outputs the coupon onto the console
resembling the actual coupon that is used in the game (see sample output).
The numbers should be printed in a tabular format and the selected numbers
should be printed in brackets.
1.e.
(15 pt)
Provide a method named fillRandom that helps the user to fill the coupon
randomly. Here, the coupon should be cleared first to resolve the problems when it
could have some marked choices. Then, exactly six different choices should be
made on this coupon.
1.f.
(10 pt)
Do not forget to write explanatory comments within your code.
Make use of appropriate indentations, and white spaces to increase readability.
You should submit both the .java file and the compiled .class file.
Name : .....................................................................
Comp 240 Quiz Programming 3
ID # : .....................................................................
May 05, 2005
2/2
Q2. (30 pt)
Write a test application “CouponTest.java” to utilize and test the Coupon class that you have created in
Q1. You may solve 2.a and 2.b within the same test application.
2.a.
(15 pt)
As a test case, create a filled coupon where the choices 1, 16, 29, 38, 44, 46 are
marked. Then using the methods that you have created, print out the comma
separated list of the selection, and the coupon layout where the selected numbers
are marked.
The output of the application should be similar to this:
Selected numbers are: 1, 16, 29, 38, 44,
[ 1]
2
3
4
5
6
7
8
10
11
12
13
14
15 [16] 17
19
20
21
22
23
24
25
26
28 [29] 30
31
32
33
34
35
37 [38] 39
40
41
42
43 [44]
[46] 47
48
49
2.b.
46
9
18
27
36
45
(15 pt)
As a second test case, continue the test application while creating an empty
coupon. Then fill this coupon randomly. Finally, print out the list of selected
numbers and the coupon layout.
A sample output should be continued as follows:
Selected numbers are: 4, 8, 18, 35, 39, 40
1
2
3 [ 4]
5
6
7 [ 8]
9
10
11
12
13
14
15
16
17 [18]
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 [35] 36
37
38 [39] [40] 41
42
43
44
45
46
47
48
49
Download