Answer to Question #287925 in Java | JSP | JSF for him

Question #287925

Define a class called Fuel_Monitor that will be used to check the

amount of fuel that is left over in a vehicle after travelling a certain distance. The class should have instance variables tankCapacity to store initial size of the tank and efficiency to store initial efficiency of the vehicle. Also, set the variable fuel_ in_ tank to zero that is used to store initial fuel in tank. Include a method that returns ini_tank_size, ini_effi and fuel_in_tank. Include an method add_fuel that calculates how much fuel can be filled depending upon the fuel already in the tank and the capacity of the tank. Also, include a method drive_distance that returns how much distance can be travelled with the fuel available in the tank with the efficiency provided. Embed your class in a test program. You should decide which variables should be public, if any


1
Expert's answer
2022-01-16T09:03:22-0500
class Main {
    public static void main(String[] args) {
        Fuel_Monitor fuelMonitor = new Fuel_Monitor(2000, 0.6);

        System.out.println("Fuel can be add: " + fuelMonitor.addFuel());
        System.out.println("Fill the fuel tank");
        fuelMonitor.setFuelInTank(fuelMonitor.addFuel());
        System.out.println("Distance that can be driven now: " + fuelMonitor.driveDistance());
    }
}

class Fuel_Monitor {

    private int tankCapacity;
    private double efficiency;
    private int fuelInTank;

    public Fuel_Monitor(int tankCapacity, double efficiency) {
        this.tankCapacity = tankCapacity;
        this.efficiency = efficiency;
        this.fuelInTank = 0;
    }

    public int addFuel() {
        return tankCapacity - fuelInTank;
    }

    public double driveDistance() {
        return fuelInTank * efficiency;
    }

    public int getTankCapacity() {
        return tankCapacity;
    }

    public double getEfficiency() {
        return efficiency;
    }

    public int getFuelInTank() {
        return fuelInTank;
    }

    public void setFuelInTank(int fuelInTank) {
        this.fuelInTank = fuelInTank;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog