PLTL week12 knowledgecheck

Document Sample
PLTL week12 knowledgecheck Powered By Docstoc
					Knowledge Check!
Today we want to get practical and make sure you are up to speed with everything
we’ve been covering. The assignment is simple. In your groups, write the class that
corresponds to the Police_car class described below:

Methods

Police_car([car_number][,top_speed]) – this is the class constructor. It
has two optional parameters for the number and top speed of the car. If one is not
provided, the default should car number should be 0 and the top speed should be
150. This class should extend the functionality of the Vehicle constructor on the next
page!

get_car_number() – this method returns the car number

toggle_siren() – this method turns the siren on and off

get_siren() – this method returns the status of the siren

check_speeding(vehicle, limit) – this method takes a vehicle and a limit
as parameters. The method to check to see if the vehicle’s speed is over the limit. If
so, then it should return “Too fast.” If the vehicle’s speed is more than 20 MPH less
than the limit, it should return “Too slow.”

check_warrant(vehicle) – this method takes a vehicle as a parameter. The
method opens a file called “warrant.txt” which has a licence plate per line. If the
vehicle’s license plate is found in the file, the vehicle has a warrant out and the
method should return “True.” Otherwise, it should return “False”.

get_dept(vehicle) – this method takes a police car as a parameter. The
method will then check the car number and return the name of the corresponding
department as follows:

       1-100 – Vice
       101-200 – Traffic
       201-300 – Homicide
       301-400 – Narcotics
       401-500 – SWAT

All other values should return “Invalid”
class Vehicle(object):
     def __init__(self, top_speed = 120, plate = "AAAAAA"):
           self.top_speed = 120
           self.speed = 0
           self.engine_on = False
           self.lights_on = False
           self.plate = plate

     def toggle_ignition(self):
          self.engine_on = not self.engine_on

     def get_engine_on(self):
          return self.engine_on

     def toggle_lights(self):
          self.lights_on = not self.lights_on

     def get_lights_on(self):
          return self.lights_on

     def change_speed(self, speed):
          if (speed < 0 or speed > self.top_speed):
                print "Invalid speed"
                return False
          else:
                self.speed = speed

     def get_speed(self):
          return self.speed

     def get_plate(self):
          return self.plate

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:2
posted:10/4/2012
language:English
pages:2