Java Reference
In-Depth Information
Is your birthday in Set3?
4 5 6 7
12 13 14 15
20 21 22 23
28 29 30 31
Enter 0 for No and 1 for Yes:
0
Is your birthday in Set4?
8 9 10 11
12 13 14 15
24 25 26 27
28 29 30 31
Enter 0 for No and 1 for Yes:
1
Is your birthday in Set5?
16 17 18 19
20 21 22 23
24 25 26 27
28 29 30 31
Enter 0 for No and 1 for Yes:
1
Your birthday is 26
Since getValue is a static method, you don't need to create an object in order to invoke it.
GuessDate.getValue(i, j, k) (line 15) returns the date at row j and column k in Set i .
The GuessDate class can be implemented as in Listing 10.10.
L ISTING 10.10 GuessDate.java
1 public class GuessDate {
2
3 {{ 1 , 3 , 5 , 7 },
4 { 9 , 11 , 13 , 15 },
5 { 17 , 19 , 21 , 23 },
6 { 25 , 27 , 29 , 31 }},
7 {{ 2 , 3 , 6 , 7 },
8 { 10 , 11 , 14 , 15 },
9 { 18 , 19 , 22 , 23 },
10 { 26 , 27 , 30 , 31 }},
11 {{ 4 , 5 , 6 , 7 },
12 { 12 , 13 , 14 , 15 },
13 { 20 , 21 , 22 , 23 },
14 { 28 , 29 , 30 , 31 }},
15 {{ 8 , 9 , 10 , 11 },
16 { 12 , 13 , 14 , 15 },
17 { 24 , 25 , 26 , 27 },
18 { 28 , 29 , 30 , 31 }},
19 {{ 16 , 17 , 18 , 19 },
20 { 20 , 21 , 22 , 23 },
21 { 24 , 25 , 26 , 27 },
22 { 28 , 29 , 30 , 31 }}};
23
24
private final static int [][][] dates = {
static field
/** Prevent the user from creating objects from GuessDate */
25
26 }
27
28
private GuessDate() {
private constructor
/** Return a date at the specified row and column in a given set */
 
 
Search WWH ::




Custom Search