• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Odometer

 
Collin Sampson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic