Question: Mechanic.java This file represents a Mechanic object. Variables All variables must be visible and editable by only the Mechanic class using appropriate visibility modifiers, getters,



Mechanic.java This file represents a Mechanic object. Variables All variables must be visible and editable by only the Mechanic 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. o String name This represents the name of the mechanic This variable must not be editable after it is first set by the constructor (Hint: what keyword allows us to do this?) double revenue This represents the amount of money made so far The default value is 0.00. No negative values are allowed. The default value should be set in the constructor (see section below). o double oilChange Price This represents the price of an oil change The default value is 44.99. No values less than 0.99 allowed. The default value should be set in the constructor (see section below). o double newTirePrice This represents the price of a new tire The default value is 59.99. No values less than 0.99 allowed. The default value should be set in the constructor (see section below). Constructors You will implement 3 constructors. For all constructors, use proper constructor chaining (from least parameters to most parameters) 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, set the attribute to its default value specified above. A constructor that takes in the name, revenue, oilChangePrice, and newTire Price of the Mechanic. o A constructor that takes in the name, oilChangePrice, and newTirePrice of the Mechanic. A constructor that only takes in the name of the Mechanic. Methods (All methods must be public unless otherwise specified) o String toString() Returns a String in the following format: "This is a mechanic named {name}. I charge ${oilChange Price) for an oil change, and I charge ${newTirePrice} for a new tire. I've made ${revenue) in revenue." The curly braces {} denote values that should be replaced with the corresponding variable(s), do not include the curly braces in your output. Use String formatting to round all floating-point values to 2 decimal places. o service (Car c) First checks if the Car parameter needs an oil change If the Car's mileage is greater than or equal to its nextOil Change then the Car needs an oil change If the Car needs an oil change, update the car's nextoilChange to the Car's current mileage plus 3000 and increase revenue by the oil Change Price Check if the Car needs new tires For each value in tirelife that is less than or equal to 0.50, increase revenue by the newTirePrice Also set the value in tirelife for that tire to 1.00. If the car doesn't need an oil change or new tires, don't change any attributes . This method does not return anything Note: You must utilize getters and setters from the Car class to access any instance variables from the Car class . variables from the Car class ShopDriver.java This file is the driver that will allow you to simulate the Mechanic objects and Car objects that will visit a Mechanic. You will do the following in the main method of your ShopDriver: Create 1 Car object called cl of type SUV with a mileage of 15000, a nextOil Change of 14600, and a tirelife array with the values {0.70, 0.32, 0.45, 0.50} Create 1 Mechanic object called ml named Raul Call ml's service method on cl Print to the console ml and cl on separate lines Now it's time to practice debugging by creating your own test scenario similar to the one above to verify your code behaves as expected. Please add code to your main method to test one nontrivial feature of your program and leave a comment explaining which requirement from the assignment your code is meant to test. Some examples of requirements that may be valuable to test are: o Verify one of your variables is set to its default value when the constructor is passed an illegal value as a parameter. o Verify a Car object that was instantiated using the copy constructor does not have reference equality with the Car object that was passed as the parameter to the copy constructor. o Verify no variables are changed by the Mechanic's service () method if the Car parameter does not need an oil change or any new tires. o Verify numCars is properly incremented when initializing a new Car object with any of the Car class constructors. Feel free to test your code yourself with more scenarios! Just make sure to clearly mark the one scenario you want us to grade with a comment
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
