Re: Help with Java Program
Re: Help with Java Program
Whe you use CODE tags it improves code readability. Your code does not seem to follow OO design practice, you should do some reading on the same.
Naming conventions are incorrect, class attributes have not been explicitly specified as private/public why ??
Your first query about run-on decimal , show a sample out put that you get and also tell us what you actually expect.
Your second query about loop, can be handled pretty easily though it isnt really neat handling with current code, lets try solving problems in given sequence. Hint for the second is you need to add a loop for reading the values and the terminating condition being when odometer reading is entered as 0.
Re: Help with Java Program
Quote:
Originally Posted by Logo
when it output the mpg and cumulative mpg i get a run-on number after the decimal.
That's because you are outputting a floating point value. If you want to limit the number of decimal places that are displayed you could use the printf(..) method. For example to limit it to 2 decimal places:
Code:
System.out.printf("Cumulative miles per gallon is %.2f", new Double(cumMPG));
Re: Help with Java Program
sorry about the program not being in code tags...i will try to convert that later tonight....Thanks for the help so far with the numbers, currently i'm getting like 24.984738474847 for mpg and cumMpg and wish to get 25.0. I will try that code you (keang) provided. As for the the other problem, somebody told me to insert a while loop so that i will be asked for the odometer, gas, and it will out put the mpg and cumMpg as long as the milleage is not 0. I having trouble finding out how to go about that, i have tried to insert while loops but i can't get any of them to work.
Re: Help with Java Program
Quote:
Originally Posted by Logo
i have tried to insert while loops but i can't get any of them to work.
We can't help you fix your loop unless you post it up here - formatted and commented.
Doing more things faster is no substitute for doing the right things...
S. R. Covey