subject

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 amount of gasoline in the fuel tank. Also supply methods getGasInTank, returning the current amount of gasoline in the fuel tank, and addGas, to add gasoline to the fuel tank. Sample usage: Car myHybrid = new Car(50); // 50 miles per gallon myHybrid. addGas(20); // Tank 20 gallons myHybrid. drive(100); // Drive 100 miles double gasLeft = myHybrid. getGasInTank(); // Get gas remaining in tank 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. This is my code, please help me fix it:

Car. java

public class Car {

// Instant Fields

private double gas;

private double efficiency;

// Constructor

public Car(double fe) {

fuelEff = fe;

gas = 0;

}

// Methods

public void addGas(double amount) {

gas = gas + amount;

}

public void drive(double distance) {

drive = drive + distance;

gas = gas - (distance / milesPerGallon);

}

public double getGasInTank() {

return gas;

}

}

Tester

class Main {

public static void main(String[] args) {

//E3.12 car

carTester();

public static void carTester() {

Car myHybrid = new Car(50);

myHybrid. addGas(20);

myHybrid. drive(100);

double gasLeft = myHybrid. getGasInTank();

System. out. println("Gas Left: " + gasLeft);

}

}

ansver
Answers: 2

Another question on Advanced Placement (AP)

question
Advanced Placement (AP), 23.06.2019 06:30
Which term defines a power shared by state and federal governments? concurrent expressed implied reserved
Answers: 1
question
Advanced Placement (AP), 24.06.2019 05:00
Ronan has been working as domestic at a large mansion since a few months. recently, he has taken his employer’s seven-year-old boy by force and held him captive. he has demanded money from his employer in return of the boy. which crime has ronan committed? a. treason b. sedition c. assault and battery d. kidnapping
Answers: 2
question
Advanced Placement (AP), 25.06.2019 03:30
When you can't determine who arrived at an intersection first, yield to the vehicle a. closest to you on the left b. closest to you on the right c. across from you d. with the largest wheelbase
Answers: 1
question
Advanced Placement (AP), 25.06.2019 04:30
Arrange the following in order from the shortest wavelength to the longest wavelength. visible light gamma rays radio waves x-ray waves microwave infrared
Answers: 1
You know the right answer?
Implement a class Car with the following properties. A car has a certain fuel efficiency (measured i...
Questions
question
History, 26.03.2021 04:10
question
Social Studies, 26.03.2021 04:10
question
Arts, 26.03.2021 04:10
question
Mathematics, 26.03.2021 04:10
Questions on the website: 13722362