Repository navigation
Expand file tree
/
Copy pathDie.java
More file actions
73 lines (59 loc) · 1.51 KB
/
Copy pathDie.java
File metadata and controls
73 lines (59 loc) · 1.51 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.Random;
public class Die {
private static final int DEFAULT_SIDES = 6;
private int faceValue;
private int sides;
private Random generator = new Random();
/**
* Construct a new Die with default sides
*/
public Die() {
this.sides = DEFAULT_SIDES;
this.faceValue = 1 + generator.nextInt(sides);
}
/**
* Generate a new random number between 1 and sides to be stored in faceValue
*/
private void throwDie() {
this.faceValue = 1 + generator.nextInt(sides);
}
/**
* @return the faceValue
*/
public int getFaceValue() {
return faceValue;
}
public void printDie() {
throwDie();
int x = this.getFaceValue();
System.out.println(" ----- ");
if(x==4||x==5||x==6) {
printTwo();
} else if(x==2||x==3) {
System.out.println("| * |");
} else {
printZero();
}
if(x==1||x==3||x==5) {
System.out.println("| * |");
} else if(x==2||x==4) {
printZero();
} else {
printTwo();
}
if(x==4||x==5||x==6) {
printTwo();
} else if(x==2||x==3) {
System.out.println("| * |");
} else {
printZero();
}
System.out.println(" ----- ");
}
private void printZero() {
System.out.println("| |");
}
private void printTwo() {
System.out.println("| * * |");
}
}