Java Reference
In-Depth Information
GuessDate
-dates: int[][][]
The static array to hold dates.
+getValue(setNo: int, row: int,
column: int): int
Returns a date at the specified row and column
in a given set.
F
IGURE
10.13
The
GuessDate
class defines data for guessing birthdays.
Assume that the
GuessDate
class is available. Listing 10.9 is a test program that uses this
class.
L
ISTING
10.9
UseGuessDateClass.java
1
import
java.util.Scanner;
2
3
public class
UseGuessDateClass {
4
public static void
main(String[] args) {
5
int
date =
0
;
// Date to be determined
6
int
answer;
7
8
// Create a Scanner
9 Scanner input =
new
Scanner(System.in);
10
11
for
(
int
i =
0
; i <
5
; i++) {
12 System.out.println(
"Is your birthday in Set"
+ (i +
1
) +
"?"
);
13
for
(
int
j =
0
; j <
4
; j++) {
14
for
(
int
k =
0
; k <
4
; k++)
15 System.out.print(
GuessDate.getValue(i, j, k)
+
" "
);
invoke static method
16 System.out.println();
17 }
18
19 System.out.print(
"\nEnter 0 for No and 1 for Yes: "
);
20 answer = input.nextInt();
21
22
if
(answer ==
1
)
23 date +=
GuessDate.getValue(i,
0
,
0
)
;
invoke static method
24 }
25
26 System.out.println(
"Your birthday is "
+ date);
27 }
28 }
Is your birthday in Set1?
1 3 5 7
9 11 13 15
17 19 21 23
25 27 29 31
Enter 0 for No and 1 for Yes:
0
Is your birthday in Set2?
2 3 6 7
10 11 14 15
18 19 22 23
26 27 30 31
Enter 0 for No and 1 for Yes: 1