Results 1 to 5 of 5
  1. #1
    Garbouw Deark is offline Member
    Join Date
    Mar 2014
    Posts
    3
    Rep Power
    0

    Default Stuck on the standard odometer lesson

    Yep, another one of these. It seems my Comp Sci teacher lacks originality (and any real ability to teach), and went with this one to 'teach' us classes. Unfortunately, the majority of the people in the class don't own a car, or a license. And she did a pretty terrible job explaining it. So, while I can do classes, I can't finish the assignment, because I don't know the equation/part-of-code-that-will-most-likely-never-be-used-again.

    What I'm trying to ask, is what do I have to do (nothing specific, please), to end up with a console that looks something like this:

    New car odometer reading: 15

    Filling Station Visit
    odometer reading: 250
    gallons to fill tank: 10

    Miles per gallon: 23.50

    Filling Station Visit
    odometer reading: 455
    gallons to fill tank: 12.5

    Miles per gallon: 16.40

    You know, the standard 'Calculate miles per gallon every stop at a gas station' thing. Please?

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Stuck on the standard odometer lesson

    First step in writing any program: think about how you would do what the program needs to do. What values do you need? What would you do with those values? The rest is easy.
    Get in the habit of using standard Java naming conventions!

  3. #3
    Garbouw Deark is offline Member
    Join Date
    Mar 2014
    Posts
    3
    Rep Power
    0

    Default Re: Stuck on the standard odometer lesson

    Okay...maybe I phrased this wrong...I literally know just about nothing concerning cars. I barely know what an odometer is. What I'm looking for is for someone to rephrase this in a more helpful manner, one that I can derive some sort of equation from.

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Stuck on the standard odometer lesson

    Oh. Well, I can explain that because I do it all the time.

    The idea is that each time you buy gasoline, you fill your tank to the top and record the mileage on your odometer. The next time you buy gasoline, the pump tells you how many gallons it took to fill the tank to the top again. By subtracting the previous odometer reading from the current one, you know how many miles you drove since your last fill-up. By dividing that distance by the amount of fuel you put in, you know how many miles per gallon you got.

    So basically your program will need a starting odometer reading, and you assume the tank is full. Then use whatever input method you've been taught to get a series of fuel amounts and odometer readings from the user.
    Get in the habit of using standard Java naming conventions!

  5. #5
    Garbouw Deark is offline Member
    Join Date
    Mar 2014
    Posts
    3
    Rep Power
    0

    Default Re: Stuck on the standard odometer lesson

    Thank you so much! I'm glad I can finally stop pounding my head against a metaphorical wall!

Similar Threads

  1. Standard input
    By Jey in forum New To Java
    Replies: 2
    Last Post: 08-18-2011, 11:31 AM
  2. Need Serious Help on Odometer exercise
    By gnng in forum New To Java
    Replies: 16
    Last Post: 03-20-2011, 07:58 PM
  3. Coded Life Lesson :)
    By MuslimCoder in forum Forum Lobby
    Replies: 7
    Last Post: 07-29-2009, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •