added lab7 ex1
This commit is contained in:
32
src/lab7_state/ex1/states/ChoiceState.java
Normal file
32
src/lab7_state/ex1/states/ChoiceState.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package lab7_state.ex1.states;
|
||||
|
||||
import lab7_state.ex1.Machine;
|
||||
import lab7_state.ex1.MachineState;
|
||||
|
||||
public class ChoiceState extends MachineState {
|
||||
public ChoiceState(Machine machine) {
|
||||
super(machine);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void returnCoin() {
|
||||
machine.returnMoney(0.25);
|
||||
machine.setCurrentState(machine.getIdleState());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void pushButton() {
|
||||
if (!machine.hasCups()) {
|
||||
System.out.println("The machine is out of cups");
|
||||
} else if (!machine.hasCoffee()) {
|
||||
System.out.println("The machine is out of coffee beans");
|
||||
} else if (machine.isJammed()) {
|
||||
System.out.println("The machine is jammed");
|
||||
} else {
|
||||
machine.makeCoffee();
|
||||
machine.setCurrentState(machine.getCoffeeReadyState());
|
||||
return;
|
||||
}
|
||||
machine.setCurrentState(machine.getServiceNeededState());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user