-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDieCup.java
More file actions
58 lines (57 loc) · 1.42 KB
/
Copy pathDieCup.java
File metadata and controls
58 lines (57 loc) · 1.42 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
//Nancy
import java.util.*;
public class DieCup
{
private Die [] dice;
private int [] values = new int [7];
public DieCup (int number){
dice = new Die [number];
rollDie (number);
}
public void rollDie (int number){
for (int i = 0; i < 7; i++)
values[i] = 0;
for (int i = 0; i < number; i++){
dice [i] = new Die();
dice[i].roll();
values[dice[i].getNumDots()] ++;
}
}
public int [] getValues (){
return values;
}
public boolean yahtzee (){
boolean a = true;
for (int k = 1; k < 7; k ++){
if (values[k] > 0){
for (int i = 1; i < 7; i++){
if (values[i] > 0 && i != k)
a = false;
}
}
}
return a;
}
public String toString (){
//format print dice too
String ans = "Dice: ";
for (Die x: dice){
ans += x.getNumDots();
ans += " ";
}
ans += "which is ";
ans += values[1];
ans += " ones, ";
ans += values[2];
ans += " twos, ";
ans += values[3];
ans += " threes, ";
ans += values[4];
ans += " fours, ";
ans += values[5];
ans += " fives, and ";
ans += values[6];
ans += " sixes.";
return ans;
}
}