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 20:20
With my drivers ed in the decision-making cycle, to decide means to a. carry out an action that has been decided b. estimate if an identified hazard will affect the driver c. pick a course of action d. pick a scanning routine
Answers: 3
question
Advanced Placement (AP), 25.06.2019 18:00
Anew moon would be directly overhead at what time
Answers: 2
question
Advanced Placement (AP), 26.06.2019 23:30
An orbit that is the most eccentric is also
Answers: 1
question
Advanced Placement (AP), 27.06.2019 03:00
Wich of the five senses is excluded as a function of the thalamus
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
Mathematics, 28.01.2020 08:31
question
English, 28.01.2020 08:31
question
Mathematics, 28.01.2020 08:31
question
Mathematics, 28.01.2020 08:31
question
Business, 28.01.2020 08:31