diff --git a/src/soon/PlayZustand.java b/src/soon/PlayZustand.java index 2a74fd6946c49ce8469d41f4c1ca1845123ed1ff..fc8bf7323c5a08220839a5ff1eacb402feaa9a3d 100644 --- a/src/soon/PlayZustand.java +++ b/src/soon/PlayZustand.java @@ -1,6 +1,6 @@ package soon; -public class PlayZustand extends Zustand { +public class PlayZustand extends PowerOn { public PlayZustand(Soon s) { super(s); diff --git a/src/soon/PowerOff.java b/src/soon/PowerOff.java new file mode 100644 index 0000000000000000000000000000000000000000..0bca94367cfd5e8e958d6845c1e7a6bc0e07ad67 --- /dev/null +++ b/src/soon/PowerOff.java @@ -0,0 +1,13 @@ +package soon; + +public class PowerOff extends Zustand { + + public PowerOff(Soon s) { + super(s); + } + + public void powerButton() { + s.setZustand(s.getStopZustand()); + System.out.println("Anschalten"); + } +} diff --git a/src/soon/PowerOn.java b/src/soon/PowerOn.java new file mode 100644 index 0000000000000000000000000000000000000000..545bd856e2a7b841025cd7ebde0cfb2730559df2 --- /dev/null +++ b/src/soon/PowerOn.java @@ -0,0 +1,13 @@ +package soon; + +public abstract class PowerOn extends Zustand { + + public PowerOn(Soon s) { + super(s); + } + + public void powerButton() { + s.setZustand(s.getPowerOffZustand()); + System.out.println("Ausschalten"); + } +} diff --git a/src/soon/Soon.java b/src/soon/Soon.java index 5e1a6931b9eab46a30efec680c07cb2e69331a9e..201c7b69229df6b8406a38319ba09d2b7913e947 100644 --- a/src/soon/Soon.java +++ b/src/soon/Soon.java @@ -3,13 +3,23 @@ package soon; public class Soon { Zustand stopZustand; Zustand playZustand; + Zustand powerOffZustand; Zustand zustand; public Soon () { stopZustand = new StopZustand(this); playZustand = new PlayZustand(this); - zustand = stopZustand; + powerOffZustand = new PowerOff(this); + zustand = powerOffZustand; + } + + public Zustand getPowerOffZustand() { + return powerOffZustand; + } + + public void powerButton() { + zustand.powerButton(); } public Zustand getStopZustand() { @@ -20,6 +30,10 @@ public class Soon { return playZustand; } + public Zustand getZustand() { + return zustand; + } + public void setZustand(Zustand zustand) { this.zustand = zustand; } @@ -32,18 +46,6 @@ public class Soon { zustand.stopButton(); } - public void startPlay() { - System.out.println("Musik an"); - } - - public void stopPlay() { - System.out.println("Musik aus"); - } - - public Zustand getZustand() { - return zustand; - } - public void volumeUpButton() { zustand.volumeUpButton(); } @@ -51,7 +53,15 @@ public class Soon { public void volumeDownButton() { zustand.volumeDownButton(); } + + public void startPlay() { + System.out.println("Musik an"); + } + public void stopPlay() { + System.out.println("Musik aus"); + } + public void volumeUp() { System.out.println("Lauter"); } diff --git a/src/soon/SoonTestDrive.java b/src/soon/SoonTestDrive.java index 23c305023a30bbaa557cf7ee3d95377b8d94222b..7e3fc47a1fa5124ea45a60f906e09080258acd3c 100644 --- a/src/soon/SoonTestDrive.java +++ b/src/soon/SoonTestDrive.java @@ -7,10 +7,12 @@ public class SoonTestDrive { Soon player = new Soon(); System.out.println(player); + player.powerButton(); player.playButton(); player.volumeUpButton(); - player.stopButton(); player.volumeDownButton(); + player.stopButton(); + player.powerButton(); } } diff --git a/src/soon/StopZustand.java b/src/soon/StopZustand.java index 9a9bc1205107203c7976f67e4b9e95d5ba699377..354c263f3e6346baed1047102739bf56d9c858ef 100644 --- a/src/soon/StopZustand.java +++ b/src/soon/StopZustand.java @@ -1,6 +1,6 @@ package soon; -public class StopZustand extends Zustand { +public class StopZustand extends PowerOn { public StopZustand(Soon s) { super(s); diff --git a/src/soon/Zustand.java b/src/soon/Zustand.java index 43a6b1955c3636c32c7f295c0f093cafe1de1993..f1ab5911767a03473535110cf50113356c44d4c4 100644 --- a/src/soon/Zustand.java +++ b/src/soon/Zustand.java @@ -3,13 +3,15 @@ package soon; public abstract class Zustand { protected Soon s; - public Zustand(Soon s) { - this.s = s; + public Zustand(Soon k) { + this.s = k; } + public void playButton() {}; public void stopButton() {}; public void volumeUpButton() {}; public void volumeDownButton() {}; public void entry() {}; public void exit() {}; + public void powerButton() {}; }