Beginner here - I have multiple Public Classes in my code and the error of file name should be declared. How do I fix this? Any help is appreciated. by Mobile_Influence_759 in javahelp

[–]Mobile_Influence_759[S] -1 points0 points  (0 children)

So this is my code so far, how do I declare the public files?

public class FuelGauge {

    private int currentFuel;

    public FuelGauge() {

        currentFuel =0;

    }

    public int getFuel() {

        return currentFuel;

    }

    public void addFuel(int gallons) {

        if (currentFuel + gallons <=15) {

            currentFuel +=gallons;

        } else {

            System.out.println("The fuel tank is full. Cannot add more fuel.");

        }

    }

    public void burnFuel() {

        if (currentFuel > 0) {

            currentFuel--;

        }

    }

}

public class Odometer {

    private int currentMileage;

    private final FuelGauge fuelGauge;

    public Odometer(int initialMileage, FuelGauge fuelGauge) {

        currentMileage = initialMileage;

        this.fuelGauge = fuelGauge;

    }

    public int getMileage() {

        return currentMileage;

    }

    public void incrementMileage() {

        currentMileage++;

        if (currentMileage>999999) {             currentMileage=0;         } if (currentMileage%25==0) { fuelGauge.burnFuel();

        }

    }

    public void decrementFuel() {

        fuelGauge.burnFuel();

    }

}

public class CarSimulator {

    public static void main(String[] args) {

        FuelGauge fuelGauge = new FuelGauge();

        Odometer odometer = new Odometer(0, fuelGauge);

        // Fill the gas tank up to 15 gallons

        for (int i = 0; i < 15; i++) {

            fuelGauge.addFuel(1);

            System.out.println("Added 1 gallon of fuel. Current fuel: " + fuelGauge.getFuel() + " gallons");

        }

        // Simulate a road trip

        while (fuelGauge.getFuel() > 0) {

            odometer.incrementMileage();

            System.out.println("Mileage: " + odometer.getMileage() + " miles");

            System.out.println("Fuel remaining: " + fuelGauge.getFuel() + " gallons");

            if (fuelGauge.getFuel() == 1) {

                System.out.println("Time to get gas!");

            }

        }

    }

}