diff --git a/wash/src/wash/control/Wash.java b/wash/src/wash/control/Wash.java index 4c29e4a..0f0f4bf 100644 --- a/wash/src/wash/control/Wash.java +++ b/wash/src/wash/control/Wash.java @@ -20,17 +20,19 @@ public class Wash { water.start(); spin.start(); - ActorThread t = null; + // Instantiated to avoid nullchecking in the interrupt inside the loop + ActorThread t = new EmptyProgram(); outer: while (true) { int n = io.awaitButton(); + t.interrupt(); // Immediately abort previous action, t != null here System.out.println("user selected program " + n); // if the user presses buttons 1-3, start a washing program // if the user presses button 0, and a program has been started, stop it switch (n) { - case 0 -> t = new WashingProgramN(io, temp, water, spin); + case 0 -> t = new WashingProgramStop(io, temp, water, spin); case 1 -> t = new WashingProgram1(io, temp, water, spin); case 2 -> t = new WashingProgram2(io, temp, water, spin); case 3 -> t = new WashingProgram3(io, temp, water, spin);