Course Home | Class Schedule | Moodle CMS | Git Submission | Perusall | Tutoring

Saint Louis University

Computer Science 1300/5001
Introduction to Object-Oriented Programming

Michael Goldwasser

Fall 2019

Computer Science Department

Homework Assignment 19

Ensure that you adhere to the policies on academic integrity.


In a moment, we propose an implementation for a Radio class. For this problem, please do not focus on whether or not this is an accurate model for the semantics of a radio. Instead, our primary concern is that there are five critical mistakes with the implementation that lead to explicit errors.

You are to identify these five errors and for each:

  1. Identify the line number of the error
  2. Explain in your own words why the existing code leads to an error
  3. Explain how the code should be modified to avoid that error

Our implementation can be download electronically (code here), if you wish to experiment, or is displayed as follows (line numbers only for reference).

 1  
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Radio:
    def init(self):
        self._powerOn = False
        self._volume = 5
        self._station = 90.7
        self._presets = [ 90.7, 92.3, 94.7, 98.1, 105.7, 107.7 ]

    def togglePower(self):
        self._powerOn = not self._powerOn

    def setPreset(self, ind):
        self._presets[ind] = _station

    def gotoPreset(self, ind):
        self._station = self._presets[self._ind]

  def increaseVolume(self):
      self._volume = self._volume + 1

    def decreaseVolume(self):
        self._volume = self._volume - 1

    def increaseStation(self)
        self._station = self._station + .2

    def decreaseStation(self):
      self._station = self._station - .2

Michael Goldwasser
CSCI 1300/5001, Fall 2019
Last modified: Sunday, 29 December 2019
Course Home | Class Schedule | Moodle CMS | Git Submission | Perusall | Tutoring