0

1.The FuelGauge Class: This class simulates a fuel gauge. It’s responsibilities are – To know the car’s current amount of fuel, in gallons. – To report the car’s current amount of fuel, in gallons. – To be able to increment the amount of fuel by 1 gallon. This simulates putting fuel in the car. (The car can hold a maximum of 15 gallons.) – To be able to decrement the amount of fuel by 1 gallon, if the amount of fuel is greater than 0 gallons. This simulates burning fuel as the car runs. 2.The Odometer Class: This class simulates the car’s odometer. It’s responsibilities are – To know the car’s current mileage. – To report the car’s current mileage. – To be able to increment the current mileage by 1 mile. The maximum mileage the odometer can store is 99,999 miles. When this amount is exceeded, the odometer resets the current mileage to 0. – To be able to work with a FuelGuage object. It should decrease the FuelGauge object’s current amount of fuel by 1 gallon for every 24 miles traveled. (The car’s fuel economy is 24 miles per gallon.) 3. Demonstrate the classes by creating a main class that creates instances of each. Simulate filling the car up with fuel, and then run a loop that increments the odometer until the car runs out of fuel. During each loop iteration, print the car’s current mileage and amount of fuel.

is what i had to do and i've got it down (at least I think lmao) but some of it is telling me like Cannot resolve symbol 'CarInstrumentSimulator' please take a look here is my fuelgauge class

public class FuelGauge {
    final static int MAXIMUM_GALLONS = 15;
    private int gallons;

    public FuelGauge() {
        gallons = 0;
    }
    public FuelGauge(int gallons) {
        if (gallons <= MAXIMUM_GALLONS) {
            this.gallons = gallons;
        } else {
            gallons = MAXIMUM_GALLONS;
        }
    }
    public int getGallons() {
        return gallons;
    }
    public void addGallons() {
        if (gallons < MAXIMUM_GALLONS) {
            gallons++;
        } else {
            System.out.println("Too much fuel");
        }
    }
    public void burnFuel() {
        if (gallons > 0) {
            gallons--;
        } else {
            System.out.println("No Fuel");
        }
    }


    public static void main(String[] args) {
        CarInstrumentSimulator carInstrumentSimulator = new CarInstrumentSimulator();
        FuelGauge fuel = carInstrumentSimulator.new FuelGauge();
        Odometer odometer = carInstrumentSimulator.new Odometer(0, fuel);
        for (int x = 0; x < FuelGauge.MAXIMUM_GALLONS; x++) {
            fuel.addGallons();
        }
        while (fuel.getGallons() > 0) {
            odometer.addMileage();
            System.out.println("Mileage: " + odometer.getMileage());
            System.out.println("Fuel level: " + fuel.getGallons() + " gallons");
            System.out.println("------------------------------");
        }
    }
}

and here is my odometer class

public class Odometer {
    public final int MAXIMUM_MILEAGE = 999999;
    public final int MPG = 24;
    private int initialMileage;
    private int mileage;
    private FuelGauge fuelGauge;

    public int Odometer(int mileage, FuelGauge fuelGauge) {
        this.initialMileage = mileage;
        this.mileage = mileage;
        this.fuelGauge = fuelGauge;
        public int getMileage () {
            return mileage;
        }
        public void addMileage () {

            if (mileage < MAXIMUM_MILEAGE) {
                mileage++;
            } else {
                mileage = 0;
            }

            int driven = initialMileage - mileage;
            if (driven % MPG == 0) {
                fuelGauge.burnFuel();
            }
        }
    }
}

Sorry if it's too long but i got to this point on my own and i am not sure why it is telling me stuff

0 Answers0