This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes I need help refining some code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I need help refining some code" Watch "I need help refining some code" New topic
Author

I need help refining some code

Derek Harper
Greenhorn

Joined: Aug 02, 2006
Posts: 25
Hi all,

I recently wrote a program to calculate the time it takes to download a file with a 56k modem. The program looks ok but I would like to refine it so that it gives me the exact time as opposed to a 'rounded off' time.

The program is below:





For example, the time it takes to download a 50MB file is 2hrs 44 mins & 6 seconds. Unfortunately the program I wrote prints out the following:




What is the best way to refine this program so that it gives me the EXACT time instead of 'rounded' numbers?


BTW....I used the "setMaximumFractionDigits()" method in the NumberFormat class but it actually increased the hour by 1. What am I doing wrong? Please help.


Thanks in advance.........

[ September 17, 2008: Message edited by: Derek Harper ]
[ September 17, 2008: Message edited by: Derek Harper ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44515
    
  34
If you are using Scanner for input, why aren't you using the % tags for output? A few details here, in the Java Tutorials, and some more in the Formatter class.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44515
    
  34
And please use the title of the posts to tell us what they are about: please look at this FAQ.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I need help refining some code
 
It's not a secret anymore!