Question: Write a program that creates a class named Car with the following details: Provide attributes: make, model, year, and color. Provide an initialization method (
Write a program that creates a class named Car with the following details:
Provide attributes: make, model, year, and color.
Provide an initialization method init to accept initial values for attributes.
Provide a class variable named counter that is incremented every time a new instance is created to keep track of the number of created cars.
Create four instances of the class Car named c c c cusing any values you like then print the value of the counter after that, which should be
Provide a class method named fromstring that creates a new instance of Car by parsing the string parameter it accepts, which has the following form: "makemodelyearcolor".
For example, c fromstringfordexplorerwhite" will create c as a Car object with ford as the value for the make, explorer as the value for the model, as the value for the year, and white as the value for the color.
Create a getter property named infothat returns a string of the format: "makemodelyearcolor".
Then, use this property to print the information.
For example:
printcinfo
will print:
fordexplorerwhite
Create a setter property for info that takes one argument named details of the following format: "makemodelyearcolor".
The property must parse the string to extract the individual details make model, year, and color and assign them to the variables of the instance. Use this property to change c using "ToyotaCamrysilver" such that:Cinfo "ToyotaCamrysilver"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
