Tianna Taylor-Albin

Greenhorn

Posts: 9

posted 4 years ago

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.

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.

posted 4 years ago

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.

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.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

Tianna Taylor-Albin

Greenhorn

Posts: 9

posted 4 years ago
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

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:

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"?

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

posted 4 years ago

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.

posted 4 years ago

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

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

posted 4 years ago
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

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.

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. |