File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Odometer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
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: 71

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://aspose.com/file-tools
 
subject: Odometer