Question: Car.java This file represents a Car object that will visit the Mechanic. Note that this Car class is different than another car class that may

 Car.java This file represents a Car object that will visit theMechanic. Note that this Car class is different than another car class

Car.java This file represents a Car object that will visit the Mechanic. Note that this Car class is different than another car class that may have been used in lecture; make sure that you don't confuse them. Variables All variables must be visible and editable by only the Car class using appropriate visibility modifiers, getters, and setters unless otherwise specified. When writing constructors and setters for this class, make sure to honor all default values and value restrictions specified below. String type This represents the type of the car as a String . For example: "Sedan", "SUV", "Coupe", "Compact", "Crossover", "Sports", etc. int mileage . This represents the number of miles on the Car's odometer Default value is 0. No negative values are allowed. The default value should be set in the constructor (see section below). int next0i1 Change This represents the mileage at which the car needs to get an oil change Default value is the current mileage plus 3000. No negative values are allowed. The default value should be set in the constructor (see section below). doublet) tirelife This represents the percentage of life left in each of the car's four tires. There should be exactly four values in this array, each holding a value between 0.00 and 1.00 0.00 (0%) means that the tire is completely used and needs to be replaced. 1.00 (100%) means that the tire is brand new. The default value for each tire is 1.00. No negative values or values above 1.00 are allowed. The array should be initialized in the constructor. int numCars This represents the total number of Car objects. This variable must be the same across all instances of the Car class (Hint: what keyword allows us to do this?) and must increase by one whenever a new Car is instantiated. Initialize this variable to 0. Note: Because this is shared among all instances, this variable should be initialized only once. Constructors You will implement 4 constructors. For all constructors except the copy constructor, proper constructor chaining (from least parameters to most parameters) should be used to maximize code reuse. The order of the parameter list must be the same as the order listed below and the type of all parameters must match the type of the corresponding attribute. If an attribute isn't provided in the parameter list or if a passed-in value does not follow the restrictions specified above (ex. negative value), set the attribute to its default value specified above. A constructor that takes in the type mileage, nextOil Change, and tirelife of the Car. You can assume the passed-in tirelife array is always of length 4 but you will need to check the values contained in it. . A constructor that takes in the type mileage, and tirelise of the car. A constructor that takes in the type, and tirelife of the car. A constructor that takes in another Car object and deep copies all of its attributes to make a new Car. Note: You should not be using constructor chaining for this constructor in order to properly deep copy all of the instance variables Methods (All methods listed must be public unless otherwise specified) int averageTireLife() Private helper method Returns the average (mean) tire life percentage of the 4 tires as an int (int) ({{sum of values in tirelite} / 4) * 100) String toString() Returns a string in the following format: "This is a car of type [type) with a mileage os {mileage} miles. I'm due for a checkup in (nextOil Change - mileage) miles, and my average tire life is (average tire life)." The curly braces {} denote values that should be replaced with the corresponding variable(s), do not include the curly braces in your output. Use the averageTirelife (helper method to get the average tire life. Hint: You must escope % signs with a preceding % sign in formatted Strings Necessary getters and setters for private instance variables that will need to be accessed from outside this class Make sure to check that restrictions for each attribute are met. Set the attribute to the default value if a restriction is not followed

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 Databases Questions!