added lab7 ex1

This commit is contained in:
2024-11-01 16:51:39 +01:00
parent 8cefde97d3
commit 8f38c89d7c
8 changed files with 248 additions and 0 deletions

View 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());
}
}