Course Home | Homework | Lab Hours | Programming | Schedule & Lecture Notes | Submit

Saint Louis University

Computer Science 150
Introduction to Computer Science

Michael Goldwasser

Fall 2005

Dept. of Math & Computer Science

Homework Assignment 04a

Defining a class

Contents:


Overview

Topic: Defining a Class
Related Reading: Notes from class
Due: 1:10pm, Tuesday 27 September 2005

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
    


Michael Goldwasser
CSCI 150, Fall 2005
Last modified: Wednesday, 28 September 2005
Course Home | Homework | Lab Hours | Programming | Schedule & Lecture Notes | Submit