Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please provide all 3 of the class files with code and remember to test a nontrivial feature in the ShopDriver.java class. I especially need help
Please provide all 3 of the class files with code and remember to test a nontrivial feature in the ShopDriver.java class. I especially need help with the ShopDriver.java class code. I do not know any other example input or output as it was not provided in the problem. Please do all of the parts and do everything you can. Thank you!
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. o String type . This represents the type of the Car as a String For example: Sedan, SUV, Coupe, Compact, Crossover, Sports, etc. O 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). o int nextoilchange 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). double[] 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 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, nextoilChange, 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. O A constructor that takes in the type, mileage, and tireLife of the Car. A constructor that takes in the type, and tireLife of the Car. O 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) oint averageTireLife () . Private helper method Returns the average (mean) tire life percentage of the 4 tires as an int (int) (({sum of values in tireLife} / 4) * 100) String toString() Returns a String in the following format: "This is a car of type {type} with a mileage of {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 escape % signs with a preceding % sign in formatted Strings o 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. 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 newTire Price . 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). o 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. O A constructor that takes in the name, revenue, oilChangePrice, and newTirePrice of the Mechanic. A constructor that takes in the name, oilChange Price, and newTirePrice of the Mechanic. O 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 nextoilChange 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 oilChange 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 . 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 nextoilchange 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. 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 The following is the expected output for the ShopDriver class (not including the test case you come up with): allisonnakazawa Allisons-MBP allisonSolution % java ShopDriver This is a mechanic named Raul. I charge $44.99 for an oil change, and I charge $59.99 for a new tire. I've made $224.96 in revenue. This is a car of type SUV with a mileage of 15000 miles. I'm due for a checkup in 3000 miles, and my average tire life is 92%Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started