-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScoreRow.java
99 lines (88 loc) · 2.36 KB
/
ScoreRow.java
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* {@link ScoreRow} represents one scoring row of the {@link ScoreSheet}.
* <p>
* "Twos", "Full House", and "Yahtzee" are examples of these scoring rows.
*
* @see ScoreSheet
* @see SumAllRow
* @see FixedAmountRow
* @see NumberRow
* @see NumOfAKindRow
* @see FullHouseRow
* @see StraightRow
* @see ChanceRow
*/
public abstract class ScoreRow {
private String name;
private int score;
/**
* Construct an instance of the abstraction {@link ScoreRow}.
*
* @param name The scoring row's name.
*/
ScoreRow(String name) {
this.name = name;
score = Yahtzee.UNSET;
}
/**
* Getter of the row's {@link #name}.
*
* @return Name of the scoring row.
*/
public String getName() {
return name;
}
/**
* Getter for the row's {@link #score}.
*
* NOTE: The score might be {@link Yahtzee#UNSET}.
*
* @return Score of the row.
*/
public int getScore() {
return score;
}
/**
* Setter for the row's {@link #score}.
*
* @param score New score for the row.
*/
public void setScore(int score) {
this.score = score;
}
/**
* Shows the {@link ScoreRow#name} for the string followed by
* {@link Yahtzee#SCORE_SPACES} spaces.
*
* @return String representation of {@link ScoreRow}.
* @see java.lang.Object#toString()
*/
public String toString() {
// Set s to be the name padded with "SCORE_SPACES"
String s = String.format("%-" + Yahtzee.SCORE_SPACES + "s--> ", name);
// Add the score if it is SET
if (score != Yahtzee.UNSET)
s += Integer.toString(score);
// Return the string representation
return s;
}
/**
* Print the {@link #toString()} to System.out.
*/
public void display() {
System.out.println(this.toString());
}
/**
* Calculates and sets the score of the row for the given {@code dice}.
*
* @param dice The dice that is getting scored.
*/
public abstract void calculateScore(Dice dice);
/**
* Checks the validity of the given {@code dice} for the scoring row.
*
* @param dice The dice that is getting verified.
* @return Whether the {@code dice} is valid for this scoring row.
*/
public abstract boolean isValid(Dice dice);
}