Question: Class Attribute budget ( class - wide variable ) : Set to 5 0 , 0 0 0 . Instance Variables price ( double )
Class Attribute
budget classwide variable: Set to
Instance Variables
price double: Car price.model string: Car make and model.pros list of strings: List of pros eg "Great gas mileage"cons list of strings: List of cons eg "Expensive repairs"propoints list of integers: Priority points for pros conpoints list of integers: Priority points for cons
Methods
Constructor:
Initializes the budget.Optionally accepts the model and price for initialization.
setcar: Sets the cars model and price.setpro: Adds a pro and its priority to the pros and propoints lists.setcon: Adds a con and its priority to the cons and conpoints lists.printit: Displays the budget, price, model, pros, cons, and their points in a formatted output.sum: Takes a list of integers eg propoints and returns the sum.compare:
Compares two car instances based on pros and cons.Formula:
ctotal cpropoints cconpointsthistotal thispropoints thisconpoints
Determines which car has the higher total.Prints totals and the recommended car to buy.
Main Program pts
Create Car Instances
Create two instances eg car and car of the Carprocon class.
Populate Data
Use the setcar method to set the model and price for each car.Add five pros and their priorities using the setpro method.Add five cons and their priorities using the setcon method.
Display Details
Use the printit method to display details of each car.
Compare Cars
Call the compare method for car passing car as the argument.The method determines which car is better and outputs the final recommendation.
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
