This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Odometer Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Odometer" Watch "Odometer" New topic
Author

Odometer

Collin Sampson
Greenhorn

Joined: Feb 27, 2012
Posts: 17
This is my first time using instance variables and the 'new' operator, so bear with me. I am trying to make a program that functions as an odometer, with a trip odometer and total odometer. I have included a method that resets the trip odometer before each trip. There are three different trips, but within each trip there are smaller trips that accumulate on the trip odometer. The user inputs mpg and miles driven on each trip. It then ouputs their mpg, trip odometer, total odometer, and gallons of gasoline used since last reset (for each trip).

I am having a problem with the total odometer. I need it to add each trip odometer for a grand total but it is only echoing the trip odometer.
Here's my code...

import java.util.*;



And the tester...


Claudiu Chelemen
Ranch Hand

Joined: Mar 25, 2011
Posts: 66

Hi Collin

The problem with your code is that you're using not one, but three different odometers.

Also, you should differentiate the trips and the odometer, as they're not the same thing.
Maybe you should consider chaning the structure of your Odometer class ? Think about an odometer, what is it supposed to store and what interactions can you have with it..

Claudiu
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Odometer
 
Similar Threads
interfaces for a lab
completely lost
Desperately need help writing Tester
Noob java assigment
error message