• Post Reply Bookmark Topic Watch Topic
  • New Topic

download speed calculator  RSS feed

 
Tianna Taylor-Albin
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to make a calculator that will calculate download speed. This is what I have so far:


It gets the minutes right, but not the seconds. I know I need to calculate the total seconds, change that into minutes, then change that into hours and have the left over minutes and seconds displayed. Please help. Any help would be appreciated. Thank you.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you are trying to do here:



since you have defined seconds to be 60 on line 32, this will always set totalSeconds to 1, which I'm pretty sure is wrong.

update:
I"m not sure your minutes are right either. I just ran it for a file of 10,000 mb, with a download speed of 1 mb/sec, and it said 1 minute.
 
Tianna Taylor-Albin
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I'm trying to do is make the calculator tell me how many hours, minutes and seconds a download would take.
I took out the minutes = 60 and it stills runs the same.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what I am trying to do (as will anyone else) is to get you to think through it. I know what the problem is, and I could tell you, but you need to work through it yourself.

I ran your most recent code. Here's what I got:

C:\slop>java DownloadTimeApp
Welcome to the Download Time Estimator

Enter file size (MB): 60
Enter download speed (MB/sec): 1
This download will take approximately 0 hours
1 minutes
60 seconds

Continue? (y/n): y

Enter file size (MB): 120
Enter download speed (MB/sec): 1
This download will take approximately 0 hours
2 minutes
120 seconds

Continue? (y/n):


So what is wrong with this? A 120 MB file WILL take 120 seconds at 1mb/second. What else would you expect in a variable named "totalSeconds"?

 
Tianna Taylor-Albin
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with it is that it only takes 2 minutes, not 2 minutes and 120 more seconds. When you enter 800 for the file size and 1 for the speed, the answer should be 13 minutes and 20 seconds. This is my second week in this class and it's my first time taking IT classes. My background is in libraries and I'm horrible at math. Please bear with me. I'm trying really hard to understand this, but I can't figure out what I'm doing wrong. I think it has something to do with variables, and maybe my math.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tianna Taylor-Albin wrote:What's wrong with it is that it only takes 2 minutes, not 2 minutes and 120 more seconds. When you enter 800 for the file size and 1 for the speed, the answer should be 13 minutes and 20 seconds. This is my second week in this class and it's my first time taking IT classes. My background is in libraries and I'm horrible at math. Please bear with me. I'm trying really hard to understand this, but I can't figure out what I'm doing wrong. I think it has something to do with variables, and maybe my math.



It's not math. It is the variables. You are using the wrong variables.

Just take out some paper and a pen -- and work out the examples manually. you should quickly see what you are doing wrong.

Henry
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
totalSeconds implies the total number of seconds - not the leftover seconds after you take out the number of minutes.

Henry has given you the best advice possible. Start with pencil and paper, and work out how YOU would do it. Then write out explicit instructions as if you were telling someone ELSE how to do it.

Then re-write those instructions as if you were telling a 10yr old child how to do it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!