Advanced Placement (AP)

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);

}

}

answer
Answers: 2

Other questions on the subject: Advanced Placement (AP)

image
Advanced Placement (AP), 23.06.2019 13:20, jaliyahmw
Iwill give anyone points if they me right now q: sustainable development is related to pollution in that a. sustainable development allows pollution to continue at current levels. b. sustainable development increases pollution of all types. c. addressing pollution is a factor in sustainable development. d. sustainable development incorporates pollution as a benefit. e. pollution levels will decrease with development.
Answers: 2
image
Advanced Placement (AP), 23.06.2019 23:30, karateprincess1
Assume that the banner needs to be 18 feet long instead of 15 feet
Answers: 1
image
Advanced Placement (AP), 25.06.2019 11:40, brayden2275
The sociological perspective focuses on what? a. general social patterns b. individual behaviors c. biological explanations d. mental processes
Answers: 1
image
Advanced Placement (AP), 25.06.2019 23:00, wulfredo67
Which composer was renowned for creating expressive gregorian chants? a. hildegard of bingen b. carlo gesualdo c. josquin desprez d. guillaume de machaut
Answers: 1
Do you know the correct answer?
Implement a class Car with the following properties. A car has a certain fuel efficiency (measured i...

Questions in other subjects: