Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Please Implement a class Car with the following properties. A car has a cer

ID: 3758717 • Letter: J

Question

Java Please

Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon or liters/ km ?pick one ) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. Supply a method drive that simulates driving the car for a certain distance, reducing the fuel level in the gas tank, and methods getGasLevel, to return the current fuel level and add Gas, to the fuel tank up. Sample usage: You may assume that the drive method is never called with a distance that consumes more than the available gas. Supply a CarTester class that tests all methods.

Explanation / Answer

class Car{
   private double gasInTank;
   private double fuelEfficiency;
   public Car(){}
   public Car(double gasInTank){
       this.gasInTank = gasInTank;
   }
   public void addGas(double gas){
       gasInTank += gas;
   }
   public void drive(double distance){
       gasInTank -= fuelEfficiency*distance;
   }
   public double getGasInTank(){
       return gasInTank;
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote