001package headfirst.command.party;
002
003public class CeilingFanOffCommand implements Command {
004        CeilingFan ceilingFan;
005        int prevSpeed;
006
007        public CeilingFanOffCommand(CeilingFan ceilingFan) {
008                this.ceilingFan = ceilingFan;
009        }
010        public void execute() {
011                prevSpeed = ceilingFan.getSpeed();
012                ceilingFan.off();
013        }
014        public void undo() {
015                switch (prevSpeed) {
016                case CeilingFan.HIGH:   ceilingFan.high(); break;
017                case CeilingFan.MEDIUM: ceilingFan.medium(); break;
018                case CeilingFan.LOW:    ceilingFan.low(); break;
019                default:                                ceilingFan.off(); break;
020                }
021        }
022}