The goal of the project is to:
Fuel gauge:
Design a set of classes that work together to simulate a cars fuel gauge and odometer. It has to
know the cars amount of fuel in gallons
report the cars amount of fuel in gallons.
be able to increment the amount of fuel b 1 gallon this simulates putting fuel in the car max 15 gallons.to be able to decrement the amount of fuel by 1 gallon if the amount of fuel is greater than 0 gallons.
odometer class:
To know the cars current mileage
to report the cars current mileage
to be able to increment the current mileage by 1 mile the maximum mileage the odometer can store is 9999999 miles when this amount is exceeded the odometer
resets the current mileage to 0
to be able to work with a fuelgauge object it should decrease the fuelgauge objects current amount of fuel by 1 for every 24 miles traveled
So this is the code and i'm not sure whats wrong, I get get it to print the amount of fuel but nothing else. I think my main method is wrong or something.
package CarSimulator; //This program is a ca[#][/#]r simulator is that works together to simulate a car's fuel gauge and odometer. //Date: 9/27/2013 public class CarSimulator { public static void main(String []args) { fuelgague gauge = new fuelgague(15); odometer odometer = new odometer(15); //While while(gauge.getAmountOfFuel () >= odometer.currentMileage ()) { gauge.decrementFuelTank (); } if(gauge.getAmountOfFuel () <= odometer.currentMileage ()) { gauge.incrementFuelTank (); } System.out.println("AmountOfFuel:" + gauge.getAmountOfFuel ()); } } package CarSimulator; public class fuelgague { public int amountOfFuel; public fuelgague(int gallons) { amountOfFuel = gallons; } public int getAmountOfFuel() { return amountOfFuel; } public void incrementFuelTank() { if (amountOfFuel < 15 ) amountOfFuel++; } public void decrementFuelTank() { if (amountOfFuel > 0 ) amountOfFuel--; } } package CarSimulator; public class odometer { public int currentMileage; public odometer(int gallons) { currentMileage = gallons; } public int currentMileage() { return currentMileage; } public void incrementFuelTank() { if (currentMileage < 999999 ) currentMileage++; if (currentMileage == 999999) currentMileage = 0; } public void decrementFuelTank() { if (currentMileage > 24 ) currentMileage--; } }