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

I would like to give me some feedback for this problem because I\'m confused Imp

ID: 3550223 • Letter: I

Question

I would like to give me some feedback for this problem because I'm confused


Implement a Car class with the following properties. A car has certain fuel efficiency (measured in km/Lt) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. Create a method drive that simulates the car for a certaindistance, reducing the fuel level in the gas tank, and methods getGasLevel() to return the current GasLevel and addGas to fill up. Sample usage:


Car myCar = new Car(15);//gas efficiency is 15 Km per liter

myCar.addGas(30); //add 30 liters of Gas

myCar.drive(100); //drive the car for 100 Km

SYstem.out.println(myCar.getGasLevel()); //should print 23.333

Explanation / Answer

import java.util.*;
//Implement a Car class with the following properties.
public class Car
{
//A car has certain fuel efficiency (measured in km/Lt) and a certain amount of fuel in the gas tank.
private double fuel_efficiency;
private double amount_of_fuel;
//The efficiency is specified in the constructor, and the initial fuel level is 0. //
public Car(double e)
{
fuel_efficiency = e;
amount_of_fuel = 0.0;
}
//Create a method drive that simulates the car for a certaindistance, reducing the fuel level in the gas tank,
public void drive(double distance)
{
amount_of_fuel = amount_of_fuel-distance/fuel_efficiency;
}
//and methods getGasLevel() to return the current GasLevel and addGas to fill up. Sample usage:
public double getGasLevel() { return amount_of_fuel; }
public void addGas(double g) { amount_of_fuel = amount_of_fuel + g; }
public static void main(String[] args)
{
Car myCar = new Car(15);//gas efficiency is 15 Km per liter
myCar.addGas(30); //add 30 liters of Gas
myCar.drive(100); //drive the car for 100 Km
System.out.println(myCar.getGasLevel()); //should print 23.333
}
}