Problem Statement
Create a class HareNap that contains the method napTime, which takes the speed of the Hare in meters per second, the speed of the Tortoise in meters per second, the length of the race in meters, and the time that the Hare wants to win the race by in seconds, and returns the time that the Hare can sleep during the race in seconds, rounded to the nearest whole second.
Definition
- Class:
- HareNap
- Method:
- napTime
- Parameters:
- int, int, int, int
- Returns:
- int
- Method signature:
- int napTime(int hareSpeed, int tortoiseSpeed, int raceLength, int winTime)
- (be sure your method is public)
Notes
- If the Hare cannot possibly beat the tortoise by winTime seconds, return 0.
- If the Hare has no time to sleep during the race, return 0.
- Round your answer to the nearest whole second. 0.5 rounds up to 1, while 0.4 rounds down to 0.
Constraints
- hareSpeed and tortoiseSpeed are between 1 and 100, inclusive.
- raceLength is between 1 and 1000, inclusive.
- winTime is between 0 and 30, inclusive.
Examples
15
1
30
5
Returns: 23
The Tortoise will finish the race in 30 seconds. Without napping, the Hare can finish the race in 2 seconds. The Hare can sleep for 23 seconds and still win the race by 5 seconds.
84
35
750
8
Returns: 5
The Tortoise will finish the race in about 21.43 seconds. Without napping, the Hare can finish the race in about 8.93 seconds. The Hare can sleep for exactly 4.5 seconds and still beat the Tortoise by 8 seconds.
60
10
127
11
Returns: 0
The Tortoise will finish the race in 12.7 seconds. Without napping, the Hare can finish the race in about 2.12 seconds. The Hare cannot beat the Tortoise by 11 seconds even if he doesn't sleep.
80
40
800
10
Returns: 0
The Tortoise will finish the race in 20 seconds. Without napping, the Hare can finish the race in 10 seconds. The Hare can win the race by 10 seconds, but has no time to nap.
90
40
468
6
Returns: 1
The Tortoise will finish the race in 11.7 seconds. Without napping, the Hare can finish the race in 5.2 seconds. The Hare can sleep for 0.5 seconds and still beat the Tortoise by 6 seconds.
49
37
982
0
Returns: 6
15
1
30
5
Returns: 23
25
35
650
3
Returns: 0
30
30
120
1
Returns: 0
20
30
600
0
Returns: 0
35
25
650
3
Returns: 4
100
100
1000
1
Returns: 0
100
99
1000
0
Returns: 0
100
91
1000
0
Returns: 1
100
40
1000
13
Returns: 2
60
10
125
10
Returns: 0
60
10
127
11
Returns: 0
90
80
40
0
Returns: 0
75
25
50
0
Returns: 1
25
75
50
0
Returns: 0
80
40
800
10
Returns: 0
84
35
750
8
Returns: 5
90
40
468
6
Returns: 1
51
24
340
3
Returns: 5
99
91
563
0
Returns: 0
97
87
422
0
Returns: 1
97
75
496
0
Returns: 1
87
49
617
0
Returns: 5
97
61
904
0
Returns: 6
35
11
8
0
Returns: 0
49
37
982
0
Returns: 6
10
60
60
10
Returns: 0
25
50
500
5
Returns: 0
1
1
1
30
Returns: 0
1
10
300
0
Returns: 0
15
1
30
30
Returns: 0
49
80
982
0
Returns: 0
25
20
4
30
Returns: 0
12
10
60
5
Returns: 0
10
9
20
5
Returns: 0
15
1
30
2
Returns: UNKNOWN-OUTPUT10291821323