-
Notifications
You must be signed in to change notification settings - Fork 23
/
NoQuarterState.java
36 lines (29 loc) · 1.01 KB
/
NoQuarterState.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
package GumballMachineOneInTenGame;
public class NoQuarterState implements State {
GumballMachine gumballMachine;
public NoQuarterState(GumballMachine gumballMachine) {
this.gumballMachine = gumballMachine;
}
@Override
public void insertQuarter() {
// we print a message
System.out.println("You inserted a quarter");
// and then change the machine's state to HasQuarterState
gumballMachine.setState(gumballMachine.getHasQuarterState());
}
@Override
public void ejectQuarter() {
// you can't get money back if you never gave it to us
System.out.println("You haven't inserted a quarter");
}
@Override
public void turnCrank() {
// you can't get a gumball if you don't pay us
System.out.println("You turned, but there's no quarter");
}
@Override
public void dispense() {
// we can't be dispensing gumballs without payment
System.out.println("You need to pay first");
}
}