Homework Assignment

Defining a class

Contents:


Overview

Topic: Defining a Class
Related Reading: Notes from class
Due:

Please make sure you adhere to the policies on academic integrity.


Problems to be Submitted (10 points)

  1. (10 points)

    Below is the for a class Radio, similar to the Television class described during lecture. Unfortunately, it doesn't work. There are five errors in this class declaration. Find all the errors and correct them. (Do not worry about volume or stations being set too high or too low.)

     1        class Radio():
     2	
     3            def init(self):
     4                self.powerOn = False
     5                self.volume = 5
     6                self.station = 88.1
     7                self.presets = [ 88.1, 92.1, 96.1, 101.1, 104.1 ]
     8                
     9            def togglePower(self):
    10                self.powerOn = not self.powerOn
    11                
    12            def setPreset(self, ind):
    13                self.presets[ind] = station
    14                
    15            def gotoPreset(self, ind):
    16                self.station = self.presets[ind]
    17                
    18            def increaseVolume(self):
    19                self.volume = self.volume + 1
    20                
    21            def decreaseVolume(self)
    22                self.volume = self.volume - 1
    23                
    24            def increaseStation(self):
    25                self.station = self.station + .2
    26                
    27           def decreaseStation(self):
    28               self.station = self.station - .2
    


Last modified: Wednesday, 28 September 2005