Menu

Please Code Java Going Create Car Class Simulate Far Car Drive Road Trip Need Complete Car Q43866548

Please code in Java

You are going to create a Car class to simulate how far a carcan drive on a road trip. To do this, you will need to completeboth the Car and the CarTester classes. For the Car class, you willuse the following variables and methods: Instance Variables:private double efficiency // this is miles per gallon privatedouble gas private double tankCapacity private doubletotalMilesDriven Constructor: public Car(double carEfficiency,double carTankCapacity) Methods: * public void addGas()- thismethod should fill the car with gas up to the tank capacity. Themethod should print `Filling up …` * public void addGas(doubleamount) – This should add amount to the tank. If the amount isgreater than the capacity, set the gas to the tank capacity. Themethod should print `Adding gas …` * public doublegetTotalMilesDriven() – returns the number of miles the car hasdriven * public void drive(double distance) – checks if car candrive that number of miles, and then adds miles to totalMilesDrivenand subtracts the amount of gas needed to go those miles. Themethod should print `Driving [distance]` or, if the distance is toofar, it should print `Can’t drive [distance]. That’s too far!` *public boolean canDrive (double distance) – returns true if the carhas gas * public double milesAvailable() – returns how many moremiles the car could drive * public double getGas() – returns theamount of gas left In creating both the Car and CarTester, be sureto check the sample output to guide your design considerations. Youwill need to have a conditional statement in the drive method todetermine if you can drive the correct distance. Also, make sureyou check that you don’t over fill the gas tank! Sample Output:Filling up … Miles available: 300.0 Driving 100.0 Milesavailable: 200.0 Adding gas … Miles available: 260.0 Can’t drive1000.0. That’s too far! Driving 200.0 Gas remaining: 3.0 TotalMiles Driven: 300.0

Expert Answer


Answer to Please code in Java You are going to create a Car class to simulate how far a car can drive on a road trip. To do this, …

OR