001package headfirst.facade.hometheater;
002
003public class CdPlayer {
004        String description;
005        int currentTrack;
006        Amplifier amplifier;
007        String title;
008
009        public CdPlayer(String description, Amplifier amplifier) {
010                this.description = description;
011                this.amplifier = amplifier;
012        }
013
014        public void on() {
015                System.out.println(description + " on");
016        }
017
018        public void off() {
019                System.out.println(description + " off");
020        }
021
022        public void eject() {
023                title = null;
024                System.out.println(description + " eject");
025        }
026
027        public void play(String title) {
028                this.title = title;
029                currentTrack = 0;
030                System.out.println(description + " playing \"" + title + "\"");
031        }
032
033        public void play(int track) {
034                if (title == null) {
035                        System.out.println(description + " can't play track " + currentTrack +
036                                        ", no cd inserted");
037                } else {
038                        currentTrack = track;
039                        System.out.println(description + " playing track " + currentTrack);
040                }
041        }
042
043        public void stop() {
044                currentTrack = 0;
045                System.out.println(description + " stopped");
046        }
047
048        public void pause() {
049                System.out.println(description + " paused \"" + title + "\"");
050        }
051
052        public String toString() {
053                return description;
054        }
055}