Problem Statement |
| Imagine an ideally elastic band of length 1 foot, one end of which is connected to a wall. A spider sits at the connected end, while the other end is carried by a man. At time 0, the man starts walking away from the wall, passing manSpeed feet per second. At the same moment, the spider (represented by a single point) starts crawling along the band, covering spiderSpeed feet per second.
Your program should return an int, representing the time in seconds, rounded to the nearest integer, when the spider will overtake the man. If this will never happen, return -1. |
|
Definition |
| Class: | FastSpider | Method: | findTime | Parameters: | double, double | Returns: | int | Method signature: | int findTime(double spiderSpeed, double manSpeed) | (be sure your method is public) |
|
|
|
|
Notes |
- | Don't forget that while the man is walking he is stretching the band, which moves the spider with it. |
- | All movement is continuous. |
|
Constraints |
- | spiderSpeed will be between 0.2 and 0.5, inclusive. |
- | manSpeed will be between 1 and 5, inclusive. |
- | The answer, prior to rounding, will not be within 0.01 of x.5 for any integer x. |
- | If the spider will ever overtake the man, it will take 1 hour (3600 seconds) or less. |
|
Examples |
0) | |
| |
1) | |
| |
2) | |
| |
3) | |
| |
4) | |
| |