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 (4) instances of the class Car named c1, c2, c3, c4(using any values you like), then print the value of the counter after that, which should be 4.
Provide a class method named from_string that creates a new instance of Car by parsing the string parameter it accepts, which has the following form: "make-model-year-color".
For example, c5= from_string("ford-explorer-2020-white") will create c5 as a Car object with ford as the value for the make, explorer as the value for the model, 2020 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: "make-model-year-color".
Then, use this property to print the information.
For example:
print(c5.info)
will print:
ford-explorer-2020-white
Create a setter property for info that takes one argument named details of the following format: "make-model-year-color".
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 c4 using "Toyota-Camry-20022-silver" such that:C4.info = "Toyota-Camry-2022-silver"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!