USING PYTHON
Please make changes/additions to thecode. Note that you are only asked to provide the modifiedinitializer and the additional methods.
1. Change all data fields to private. Please only provide themodified initializer. (5 pts)
2. Add an instance methodnamed setStatus. setStatus method setsthe instance to status by taking informationof channel, volumneLevel,and on as arguments. Pleasemake sure that the channel and volumnLevel validity check, as inthe code below, should be maintained. (10 pts)
3. Add an instance method named getStatus, that returns all datafields as an instance's status. (5 pts)
class TV: definit__(self): self.channel 1 # Default channel is 1 self.volume Level = 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.volumeLevel def setVolume (self, volume Level): if self.on and \ 1 <= self.volume Level <= 7: self.volume Level 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.volume Level < 7: self.volume Level += 1 def volume Down (self): if self.on and self.volume Level > 1: self.volume Level -= 1
USING PYTHON Please make changes/additions to the code. Note that you are only asked to provide the modified initializer
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am