Car will contain three member attributes; the first two are strings, the third is an int. Class
Question:
Car will contain three member attributes; the first two are strings, the third is an int.
Class Car Spec
Instance Members:
(string) make
(string) color
(int) doors
A valid make can be either a Volkswagen, Honda or Kia. A valid color can be either blue, red, white or black. A valid int can be only a 2 or a 4. These constraints represent the values that your class will allow any of its respective string and int attributes to be set to.
Parameter Error Checking: You can assume valid parameter values for the constructor. Do validate client parameters for the mutator methods. Mixed character case is allowed for string attributes (e.g. honda, Honda, hondA, HONDA are all valid parameter for the make attribute); int attributes can only be a 2 or a 4. If a string parameter is invalid set the attribute to none. If an int parameter is invalid set the attribute to 0. Have mutators return a Boolean value to indicate whether or not the update was successful.
Suggest: Create a list of valid options, test if the parameter is in the list. Use string methods to simplify the checking needed (e.g. str.upper(), etc.).
Tips and Requirements
1. Import your class into your demo source file.
Example: Say that Amy cheng's class and demo source files are:
amyChengOhlonecar.py
amyChengOhlonedemo.py
In her demo source file, the import statement needed is:
from amyChengOhlonecar import Car
2. Document your class methods.
3. Be sure that all output is descriptive. Use labels to differentiate your output sections and full sentences in your mutator/accessor tests.
4. No user input should be done in this program.
5. PEP 8 Style guide for classnames is to use the CapWords convention (e.g. use Car for a single word class name).
Testing Specifications
Define a main function in your demo source file.
Instantiate two Car objects, using valid arguments.
Immediately display both objects.
Make three accessor calls to demonstrate that the get methods work.
Mutate one or more members of an object.
Do four explicit mutator tests. For each, call a mutator in an if/else statement which prints one message if the call is successful and a different message if the call fails.
Display all objects a second time.
Here is a sample run:
***Instantiating 2 objects
Here is car 1: ('Volkswagen', 'blue', 2)
Here is car 2: ('Kia', 'black', 4)
***Testing accessors
Car 1 make is: Volkswagen
Car 1 color is: blue
Car 1 model is: 2 door
***Testing mutators
make car 1 update succeeded
('Honda', 'blue', 2)
color car 1 update succeeded
('Honda', 'red', 2)
doors car 1 update succeeded
('Honda', 'red', 4)
Sorry, that make is not an option ('none', 'red', 4)
Sorry, that color is not an option ('none', 'none', 4)
Sorry, that door number is not an option ('none', 'none', 0)
That color update is an option ('Kia', 'white', 4)
***Final display
Here is car 1: ('none', 'none', 0)
Here is car 2: ('Kia', 'white', 4)
lambleg@newton:~/cis117/cs49/a9/b/t2$ vi cardemo.py
lambleg@newton:~/cis117/cs49/a9/b/t2$ python3 cardemo.py
***Instantiating 2 objects
Here is car 1: ('Volkswagen', 'blue', 2)
Here is car 2: ('Kia', 'black', 4)
***Testing accessors
Car 1 make is: Volkswagen
Car 1 color is: blue
Car 1 model is: 2 door
***Testing mutators
make car 1 update succeeded
('Honda', 'blue', 2)
color car 1 update succeeded
('Honda', 'red', 2)
doors car 1 update succeeded
('Honda', 'red', 4)
Sorry, that make is not an option ('none', 'red', 4)
Sorry, that color is not an option ('none', 'none', 4)
Sorry, that door number is not an option ('none', 'none', 0)
That color update is an option ('Kia', 'white', 4)
***Final display
Here is car 1: ('none', 'none', 0)
Here is car 2: ('Kia', 'white', 4)
Probability and Statistics for Engineers and Scientists
ISBN: 978-0495107576
3rd edition
Authors: Anthony Hayter