Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: What Did I Do Wrong With My Code?

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What Did I Do Wrong With My Code?

    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--; 
    } 
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,714
    My Mood
    Mellow
    Thanks
    172
    Thanked 622 Times in 609 Posts

    Default Re: What Did I Do Wrong With My Code?

    Yes, your main() method does what it does and no more. What else would you like it to do?

Similar Threads

  1. What's wrong with my code?
    By shen in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 18th, 2013, 06:34 AM
  2. what is wrong with my code
    By BLUEJ in forum Java Theory & Questions
    Replies: 4
    Last Post: January 11th, 2013, 03:40 PM
  3. what is wrong with my code
    By BLUEJ in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 10th, 2013, 06:52 PM
  4. what is wrong with my code?
    By bmb in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 7th, 2011, 09:03 AM
  5. what's wrong with this code
    By gcsekhar in forum Java Networking
    Replies: 5
    Last Post: July 21st, 2011, 06:01 AM