33 lines
946 B
Java
33 lines
946 B
Java
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());
|
|
}
|
|
}
|