python programming
Posted: Fri Jul 08, 2022 6:38 am
python programming
Below is the TV class we covered in the class. Please make changes/additions to the code. Note that you are only asked to provide the modified initializer and the additional methods. 1. Change all data fields to private. Please only provide the modified initializer. (5 pts) 2. Add an instance method named setStatus.setStatus method sets the instance to status by taking information of channel, volumneLevel, and on as arguments. Please make sure that the channel and volumnLevel validity check, as in the code below, should be maintained. (10 pts) 3. Add an instance method named getStatus, that returns all data fields as an instance's status. (5 pts) class TV: definit__(self): self.channel = 1 # Default channel is 1 self.volumeLevel = 1 # Default volume level is 1 self.on False # By default TV is off def turnOn(self): self.on True def turnOff(self): self.on False def getChannel(self): return self.channel def setChannel(self, channel): if self.on and 1 <= self.channel <= 120: self.channel channel.
def getVolume Level(self): return self.volume Level def setVolume (self, volumeLevel): if self.on and \ 1 <= self.volume Level <= 7: self.volumeLevel = volumeLevel def channelUp (self): if self.on and self.channel < 120: self.channel += 1 def channelDown (self): if self.on and self.channel > 1: self.channel - 1 def volumeUp (self): if self.on and self.volumeLevel < 7: self.volumeLevel += 1 def volume Down (self): if self.on and self.volumeLevel > 1: self.volume Level = 1
Below is the TV class we covered in the class. Please make changes/additions to the code. Note that you are only asked to provide the modified initializer and the additional methods. 1. Change all data fields to private. Please only provide the modified initializer. (5 pts) 2. Add an instance method named setStatus.setStatus method sets the instance to status by taking information of channel, volumneLevel, and on as arguments. Please make sure that the channel and volumnLevel validity check, as in the code below, should be maintained. (10 pts) 3. Add an instance method named getStatus, that returns all data fields as an instance's status. (5 pts) class TV: definit__(self): self.channel = 1 # Default channel is 1 self.volumeLevel = 1 # Default volume level is 1 self.on False # By default TV is off def turnOn(self): self.on True def turnOff(self): self.on False def getChannel(self): return self.channel def setChannel(self, channel): if self.on and 1 <= self.channel <= 120: self.channel channel.
def getVolume Level(self): return self.volume Level def setVolume (self, volumeLevel): if self.on and \ 1 <= self.volume Level <= 7: self.volumeLevel = volumeLevel def channelUp (self): if self.on and self.channel < 120: self.channel += 1 def channelDown (self): if self.on and self.channel > 1: self.channel - 1 def volumeUp (self): if self.on and self.volumeLevel < 7: self.volumeLevel += 1 def volume Down (self): if self.on and self.volumeLevel > 1: self.volume Level = 1