M07 Assignments

Introduction

The lessons for M07 focus on building classes as part of OOP (Object Oriented Programming). Exercises #1 and #2 both require an extra file to define a Python class, which is then imported into the main program.

M07 Assignments

General Requirements

Classes should be defined in separate files, and not be part of the main program.

  • Classes should be defined in separate files, and not be part of the main program
  • Prefix your class file name with your name or initials, such as DRM_Car. Note that the Python convention is to name classes starting with an uppercase letter.

Exercise #1 (Drive a Car)

Create a program that simulates driving a car. The user (driver) should be able to perform at least four (4) actions:

  1. Start the engine
  2. Accelerate: increase the speed by 5 MPH
  3. Brake: decrease the speed by 5 MPH
  4. Stop the engine

Obviously, since this is a car, the driver cannot accelerate unless the engine has been started. And once the engine is stopped, the car also cannot move. Some other requirements:

  • Keep track of and display the speed to the driver
  • The car cannot go faster than 65 MPH
  • Braking when the speed is zero does nothing
  • All the functions for controlling the car should be in the Car class
  • The driver actions (entries or buttons for controlling the engine and speed) can be in the main program

This does not have to be a GUI program. It can be done in a modular, non-GUI program.

Extra Credit:

  • Build a GUI Program: (10 points)
  • Randomly (maybe once in every 5 tries) have the engine fail to start on some tries (5 points)
  • Let the user turn left or right and display their direction. Start the car going north (10 points)
  • Let the user turn on/off a booster, and while on increase the speed by 10 MPH (although braking is the same) (10 points)

Testing: Your car activity results should look similar to the image below.

Car Activity Results
Figure 1: Car Activity Results

Exercise #2 (Run a Pet Hotel)

Write a program to manage "customers" coming to your Pet Hotel. Create two separate files for custom classes:

  • a Customer class named yourname_Customer, such as DRM_Customer()
  • a Hotel class named yourname_Hotel, such as DRM_Hotel()

The Hotel class should be able to do the following:

  • Check-In a customer to a specific room
  • Check-Out a customer
  • Display the count of current customers
  • Display a list of current customers

The Customer class should contain the following:

  1. Name
  2. Customer_Type (dog, cat, goat, pig...)
  3. Size (small, medium, large...)
  4. Length_Of_Stay (in Days)
  5. Room Number

This does not have to be a GUI program, but it should be modular. When a customer checks in, collect the five attributes above. Submit the customer record to the Hotel CheckIn() method. The Hotel class should store the new customer record in an array, such as currentCustomers. When a customer checks out, call the Hotel CheckOut method to remove the customer from the array. If the user requests the count or list of current customers, call a method in the Hotel class to provide the necessary information.

Extra Credit:

  • Calculate the room charge when the customer checks out (days * rate): (5 points)
  • Store all customer registrations and checkouts in a CSV file, named yourname_hotel_activity.csv [Have extra fields in the file for action ("check-in", "check-out") and charges (10 points)
  • Prevent someone checking into an already occupied room (15 points)