This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma 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


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: 43891
    
  32
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: 43891
    
  32
And please use the title of the posts to tell us what they are about: please look at this FAQ.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: I need help refining some code
 
It's not a secret anymore!