Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I need help refining some code

 
Derek Harper
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48394
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48394
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And please use the title of the posts to tell us what they are about: please look at this FAQ.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic