-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandChoice.java
More file actions
71 lines (63 loc) · 1.68 KB
/
HandChoice.java
File metadata and controls
71 lines (63 loc) · 1.68 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
import java.util.HashMap;
/**
* Lab 8
*
* An enumeration containing the possible hand choices that a player can make
* in Rock-Paper-Scissors.
*
* @author Stephen
* @version 2018-03-12
*/
public enum HandChoice
{
/**
* The Player chooses Rock.
*/
ROCK,
/**
* The Player chooses Paper.
*/
PAPER,
/**
* The Player chooses Scissors.
*/
SCISSORS;
/**
* Maps a Hand choice to the Hand choice that it wins against.
* I.e. a key in the strength map wins against the associate value.
* E.g. you might put the pair ROCK, SCISSORS into the map, because
* ROCK wins against SCISSORS. ROCK would be the key and SCISSORS would
* be the associated value.
*/
private static final HashMap<HandChoice, HandChoice> CHOICE_MAP;
/* This is the static initializer, run when the class is first loaded. */
static
{
CHOICE_MAP = new HashMap<HandChoice, HandChoice>();
// Populating the map with the Hand Choices that win against eachother
CHOICE_MAP.put(ROCK, SCISSORS);
CHOICE_MAP.put(SCISSORS, PAPER);
CHOICE_MAP.put(PAPER, ROCK);
}
/**
* Method that gives the hand choice that this hand choice wins against.
*
* @return The HandChoice that this type wins against. e.g. if the enum
* is type Rock, the result of winsAgainst should be Scissors.
*/
public HandChoice winsAgainst()
{
return CHOICE_MAP.get(this);
}
/**
* Returns the enum's name in lowercase.
*
* @return The name of the enum as a lowercase string.
*
@Override
*/
public String toString()
{
return name().toLowerCase();
}
}