Question
I am working on a Java project building a Car class and accompanying constructors and methods... However, I've been instructed to add more components and
I am working on a Java project building a Car class and accompanying constructors and methods... However, I've been instructed to add more components and need help with where and how to add them to the existing code...
This is the existing code:
____________________________________________________________________________________________________________
import java.text.DecimalFormat;
public class Car
{ public void main (String [] args){} private String make; private String model; private int y; private double mpg; private double mileageNextOilChange; private double odometer; private double gasGauge; private static final double TANK_CAPACITY = 12.5; private static final int MILES_BETWEEN_OIL_CHANGE = 5000; private static DecimalFormat df = new DecimalFormat("###,##0.00");
public Car() { make = "Ford"; model = "Explorer"; y = 2020; mpg = 29.0; gasGauge = TANK_CAPACITY; odometer = 0.0; mileageNextOilChange = MILES_BETWEEN_OIL_CHANGE; } public Car (String make, String model, int y, double mpg) { this.make = make; this.model = model; this.y = y; this.mpg = mpg; gasGauge = TANK_CAPACITY; odometer = 0.0; mileageNextOilChange = MILES_BETWEEN_OIL_CHANGE; }
public String getMake() { return make; }
public String getModel() { return model; }
public int getYear() { return y; }
public double getMpg() { return mpg; }
public double getMileageNextOilChange() { return mileageNextOilChange; }
public double checkOdometer() { return odometer; }
public double checkGasGauge() { return gasGauge; }
public void setMake(String make) { this.make = make; }
public void setModel(String model) { this.model = model; }
public void setYear(int y) { this.y = y; }
public void setMpg(double value) { this.mpg = value; }
public void honkHorn() { System.out.println("Beep Beep!"); } }
_______________________________________________________________________________________________
I have been asked to add the following:
More Methods - continuation
Note:
The following methods should output simple text messages on the screen for feedback, when appropriate. ALWAYS include the make, model and year of the car when printing messages about the car. Use the DecimalFormat class to format the odometer and gas in tank to include the commas and the two decimals as needed.
- public void addGas (double gallons) add the provided input parameter gallons of gas to the tank. Check for three possibilities, 1) provide a warning message if the value of the input parameter is negative and do not modify the gas tank; 2) provide a warning message if the number of gallons entered as input parameter results in the tank overflowing but still fill the tank; or 3) add the provided number of gallons to the tank. For all conditions, print a message showing the amount of gas in the tank after the fill up. Examples:
- Ford Explorer 2020 gallons cannot be a negative number - Gas in Tank after the fill up: 12.36
- Ford Explorer 2020 tank overflowed - Gas in Tank after the fill up: 12.50
- Ford Explorer 2020 added gas: 2.00 - Gas in Tank after the fill up: 11.05
- public void drive (double miles) this method is used to drive a given number of miles. It checks three possibilities: 1) print a warning message if the parameter is negative and do not update the instance of the Car; 2) print a warning message if the car runs out of gas during the trip and the miles driven. Only add the actual miles driven before running out of gas to the odometer and update the gas in the tank. Or 3) modify the odometer and amount of gas in the tank to reflect the miles driven and print an appropriate message. Think carefully about the expressions to update the gas in the tank and the odometer.
Examples:
- Ford Explorer 2020 cannot drive negative miles.
- Ford Explorer 2020 ran out of gas after driving 320.50 miles.
- Ford Explorer 2020 drove 100.00 miles.
- public void changeOil ( ) - set the oil change reminder to 5,000 miles from the current odometer reading. Print an appropriate message that the oil was changed and when it should be next changed.
Example:
Ford Explorer 2020 oil changed, next mileage to change oil is: 15,424.50
- public void checkOil ( ) Print one of two options depending on how the odometer compares to the next oil change reminder: 1) It is time to change the oil, or 2) Oil is OK, no need to change.
Examples:
- Ford Explorer 2020 - It is time to change the oil.
- Ford Explorer 2020 - Oil is OK, no need to change.
- public String toString ( ) return (dont print) a formatted String of the car. Use the DecimalFormat class to format the odometer and gas in tank to include the commas and the two decimals as needed.
Example:
Ford Explorer 2020 Odometer: 424.50 Gas in Tank: 12.36
- public boolean equals (Car other) return true if the make, model and year of a car are the same as the make, model and year of the other car passed as input parameter. Return false otherwise.
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