|
| 1 | +class Amplifier: |
| 2 | + def __init__(self, description): |
| 3 | + self.description = description |
| 4 | + self.tuner = None |
| 5 | + self.player = None |
| 6 | + |
| 7 | + def __str__(self): |
| 8 | + return self.description |
| 9 | + |
| 10 | + def on(self): |
| 11 | + print(f"{self.description} on") |
| 12 | + |
| 13 | + def off(self): |
| 14 | + print(f"{self.description} off") |
| 15 | + |
| 16 | + def set_stereo_sound(self): |
| 17 | + print(f"{self.description} stereo mode on") |
| 18 | + |
| 19 | + def set_surround_sound(self): |
| 20 | + print(f"{self.description} surround sound on (5 speakers, 1 subwoofer)") |
| 21 | + |
| 22 | + def set_volume(self, level): |
| 23 | + print(f"{self.description} setting volume to {level}") |
| 24 | + |
| 25 | + def set_tuner(self, tuner): |
| 26 | + print(f"{self.description} setting tuner to {tuner}") |
| 27 | + self.tuner = tuner |
| 28 | + |
| 29 | + def set_streaming_player(self, player): |
| 30 | + print(f"{self.description} setting Streaming player to {player}") |
| 31 | + self.player = player |
| 32 | + |
| 33 | + |
| 34 | +class Tuner: |
| 35 | + def __init__(self, description, amplifier): |
| 36 | + self.description = description |
| 37 | + self.amplifier = amplifier |
| 38 | + self.frequency = None |
| 39 | + |
| 40 | + def __str__(self): |
| 41 | + return self.description |
| 42 | + |
| 43 | + def on(self): |
| 44 | + print(f"{self.description} on") |
| 45 | + |
| 46 | + def off(self): |
| 47 | + print(f"{self.description} off") |
| 48 | + |
| 49 | + def set_frequency(self, frequency): |
| 50 | + print(f"{self.description} setting frequency to frequency") |
| 51 | + self.frequency = frequency |
| 52 | + |
| 53 | + def set_am(self): |
| 54 | + print(f"{self.description} setting AM mode") |
| 55 | + |
| 56 | + def set_fm(self): |
| 57 | + print(f"{self.description} setting FM mode") |
| 58 | + |
| 59 | + |
| 60 | +class StreamingPlayer: |
| 61 | + def __init__(self, description, amplifier): |
| 62 | + self.description = description |
| 63 | + self.amplifier = amplifier |
| 64 | + self.current_chapter = 0 |
| 65 | + self.movie = None |
| 66 | + |
| 67 | + def __str__(self): |
| 68 | + return self.description |
| 69 | + |
| 70 | + def on(self): |
| 71 | + print(f"{self.description} on") |
| 72 | + |
| 73 | + def off(self): |
| 74 | + print(f"{self.description} off") |
| 75 | + |
| 76 | + def play(self, arg): |
| 77 | + if isinstance(arg, str): |
| 78 | + self.movie = arg |
| 79 | + self.current_chapter = 0 |
| 80 | + print(f'{self.description} playing "{self.movie}"') |
| 81 | + elif isinstance(arg, int): |
| 82 | + if self.movie is None: |
| 83 | + print(f"{self.description} can't play chapter {arg} no movie selected") |
| 84 | + else: |
| 85 | + self.current_chapter = arg |
| 86 | + print( |
| 87 | + f'{self.description} playing chapter {self.current_chapter} of "{self.movie}"' |
| 88 | + ) |
| 89 | + |
| 90 | + def stop(self): |
| 91 | + self.current_chapter = 0 |
| 92 | + print(f'{self.description} stopped "{self.movie}"') |
| 93 | + |
| 94 | + def pause(self): |
| 95 | + print(f'{self.description} paused "{self.movie}"') |
| 96 | + |
| 97 | + def set_two_channel_audio(self): |
| 98 | + print(f"{self.description} set two channel audio") |
| 99 | + |
| 100 | + def set_surround_audio(self): |
| 101 | + print(f"{self.description} set surround audio") |
| 102 | + |
| 103 | + |
| 104 | +class CdPlayer: |
| 105 | + def __init__(self, description, amplifier): |
| 106 | + self.description = description |
| 107 | + self.current_track = 0 |
| 108 | + self.amplifier = amplifier |
| 109 | + self.title = None |
| 110 | + |
| 111 | + def __str__(self): |
| 112 | + return self.description |
| 113 | + |
| 114 | + def on(self): |
| 115 | + print(f"{self.description} on") |
| 116 | + |
| 117 | + def off(self): |
| 118 | + print(f"{self.description} off") |
| 119 | + |
| 120 | + def play(self, arg): |
| 121 | + if isinstance(arg, str): |
| 122 | + self.title = arg |
| 123 | + self.current_track = 0 |
| 124 | + print(f'{self.description} playing "{self.title}"') |
| 125 | + elif isinstance(arg, int): |
| 126 | + if self.title is None: |
| 127 | + print(f"{self.description} can't play track {self.current_track}, no cd inserted") |
| 128 | + else: |
| 129 | + self.current_track = arg |
| 130 | + print(f'{self.description} playing track {self.current_track}') |
| 131 | + |
| 132 | + def eject(self): |
| 133 | + print(f'{self.description} eject') |
| 134 | + |
| 135 | + def stop(self): |
| 136 | + print(f'{self.description} stopped') |
| 137 | + |
| 138 | + def pause(self): |
| 139 | + print(f'{self.description} paused "{self.title}"') |
| 140 | + |
| 141 | + |
| 142 | +class Projector: |
| 143 | + def __init__(self, description, player): |
| 144 | + self.description = description |
| 145 | + self.player = player |
| 146 | + |
| 147 | + def __str__(self): |
| 148 | + return self.description |
| 149 | + |
| 150 | + def on(self): |
| 151 | + print(f"{self.description} on") |
| 152 | + |
| 153 | + def off(self): |
| 154 | + print(f"{self.description} off") |
| 155 | + |
| 156 | + def wide_screen_mode(self): |
| 157 | + print(f"{self.description} in widescreen mode (16x9 aspect ratio)") |
| 158 | + |
| 159 | + def tv_mode(self): |
| 160 | + print(f"{self.description} in tv mode (4x3 aspect ratio)") |
| 161 | + |
| 162 | + |
| 163 | +class Screen: |
| 164 | + def __init__(self, description): |
| 165 | + self.description = description |
| 166 | + |
| 167 | + def __str__(self): |
| 168 | + return self.description |
| 169 | + |
| 170 | + def up(self): |
| 171 | + print(f"{self.description} going up") |
| 172 | + |
| 173 | + def down(self): |
| 174 | + print(f"{self.description} going down") |
| 175 | + |
| 176 | + |
| 177 | +class TheaterLights: |
| 178 | + def __init__(self, description): |
| 179 | + self.description = description |
| 180 | + |
| 181 | + def __str__(self): |
| 182 | + return self.description |
| 183 | + |
| 184 | + def on(self): |
| 185 | + print(f"{self.description} on") |
| 186 | + |
| 187 | + def off(self): |
| 188 | + print(f"{self.description} off") |
| 189 | + |
| 190 | + def dim(self, level): |
| 191 | + print(f"{self.description} dimming to {level} %") |
| 192 | + |
| 193 | + |
| 194 | +class PopcornPopper: |
| 195 | + def __init__(self, description): |
| 196 | + self.description = description |
| 197 | + |
| 198 | + def __str__(self): |
| 199 | + return self.description |
| 200 | + |
| 201 | + def on(self): |
| 202 | + print(f"{self.description} on") |
| 203 | + |
| 204 | + def off(self): |
| 205 | + print(f"{self.description} off") |
| 206 | + |
| 207 | + def pop(self): |
| 208 | + print(f"{self.description} popping popcorn!") |
0 commit comments