-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputs.java
36 lines (29 loc) · 817 Bytes
/
Inputs.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
import java.util.Random;
public enum Inputs {
NICKEL(5), DIME(10), QUARTER(25), DOLLAR(100),
TOOTHPASTE(200), CHIPS(75), SODA(100), SOAP(50),
ABORT_TRANSACTION {
public int amount() { // Disallow
throw new RuntimeException("ABORT.amount()");
}
},
STOP { // This must be the last instance.
public int amount() { // Disallow
throw new RuntimeException("SHUT_DOWN.amount()");
}
};
int value; // In cents
Inputs(int value) {
this.value = value;
}
Inputs() {
}
int amount() {
return value;
}; // In cents
static Random rand = new Random(47);
public static Inputs randomSelection() {
// Don’t include STOP:
return values()[rand.nextInt(values().length - 1)];
}
}