The lessons for M05 concentrate on object-oriented programming (OOP), so every program should include one or more object classes.
M05 Exercise #1 (Drive My Car)
- Create a Car class as a separate file
- The Car class should include the following attributes: make, model, year (all strings): make is the same as manufacturer, such as "Nissan" model is the name of a group, such as "Camry"; year is the 4-digit model year, such as "2019"
- The Car _init_ function should include parameters for year, make and model, so when the object is instantiated, you can define the year, make and model
- The Car class should have 4 functions (besides _init_) to get the car info (year,make,model), get the current speed, accelerate and brake
- The accelerate and brake methods should increase and decrease the current speed by 5 MPH each time they are called
- After displaying the standard program banner, create a Car object (setting the year, make and model)
- Create your car object with whatever year, make and model your prefer.
- Retrieve and display the year, make and model (You may return these attributes as separate values, OR as a single string)
- Have the program accelerate 5 times and and brake 5 times, displaying the current speed after each action
You should not need to use any global variables. Keep your main() function as clean as possible. Create your car object in its own function and pass it to the functions that need to use it.
M05 Exercise #3 (Convert Temperature)
This requires a GUI program. It is very similar to the samples in Chapter 13 related to calculating kilometers.
- Use the Kilometer Conversion program as a template
- Create a GUI class. This does NOT need to be a separate .py file
- Your program should display a window with a data entry textbox, a label explaining what should be entered, a label to display the conversion result, and at least one button to trigger the calculation.
- The program should accept an integer or decimal entry as a Celsius temperature, and calculate the Fahrenheit equivalent temperature.
- Add a second button to close the window (destroy the window).
- The result of the conversion calculation should be displayed in the UI (use a StringVar() variable). Do not display a popup message for the result.
- 10 points of extra credit is available for using 2 buttons to convert the base temperature entry from Celsius->Fahrenheit or Fahrenheit->Celsius
- Test data: Celsius 22 should convert to 71.6 Fahrenheit; Celsius 28 should convert to 82.4 Fahrenheit; Fehrenheit 90 converts to 32.2 Celsius