Problem Statement
When you race it is nice to have a time in mind that you'd like to be able to finish your race in. You are somewhat new to running and have only run two races of different distances. You are running a third race soon, and you want to use this equation to give you an estimate of how fast you should run. Since your upcoming race is a distance that falls between your first and second races' distances, you know this approximation will probably be fairly accurate. Create a class RaceApproximator with a method timeToBeat that takes
Definition
- Class:
- RaceApproximator
- Method:
- timeToBeat
- Parameters:
- int, int, int, int, int
- Returns:
- String
- Method signature:
- String timeToBeat(int d1, int t1, int d2, int t2, int raceDistance)
- (be sure your method is public)
Notes
- In C++ e^x can be done with exp(x), and the natural log, ln(x), can be done with log(x), both functions are in math.h.
- In C# e^x can be done with Math.Exp(x), and the natural log, ln(x), can be done with Math.Log(x). The Math class is in the System namespace.
- In Java e^x can be done with Math.exp(x), and the natural log, ln(x), can be done with Math.log(x).
- In Visual Basic e^x can be done with Exp(x), and the natural log, ln(x), can be done with Log(x), both functions are in the System.Math namespace.
Constraints
- d1, t1, d2, t2, and raceDistance will all be between 1 and 10000, inclusive.
- d1 will be less than d2
- t1 will be less than t2
- raceDistance will be greater than d1 and less than d2
- To make the approximation reliable, all speeds (distance/time) will be between 1 meter/second and 10 meters/second, inclusive.
- To avoid rounding errors, the return will never be within 1e-9 of an integer value.
Examples
800
118
5000
906
1500
Returns: "0:03:57"
Suzy Favor Hamilton's times for 800 meters and 5000 meters indicate that she should run 1500 meters in 3:57, which, in fact, is her time for 1500 meters.
400
65
1600
350
800
Returns: "0:02:30"
You can run 400 meters in 65 seconds, and 1600 meters in 5 minutes and 50 seconds, so you can probably run 800 meters in about 2 minutes and 30 seconds.
1600
299
10000
2360
5000
Returns: "0:18:00"
100
17
10000
4500
9000
Returns: "1:06:00"
1
1
10000
9999
5000
Returns: "1:23:19"
1576
1382
7591
4085
5475
Returns: "0:54:21"
900
186
9953
7887
4848
Returns: "0:42:49"
822
812
7909
7867
5289
Returns: "1:27:34"
6030
5200
9367
8053
8322
Returns: "1:59:20"
2116
522
4723
1073
4399
Returns: "0:16:46"
3616
2102
8316
3707
5965
Returns: "0:49:16"
1853
1416
1982
1623
1900
Returns: "0:24:49"
1866
1105
6686
5780
3123
Returns: "0:35:54"
3835
2140
5760
4525
3967
Returns: "0:37:57"
6248
5500
9593
6066
8652
Returns: "1:38:44"
2213
2147
7729
3828
5758
Returns: "0:55:40"
2266
1581
4246
4184
3263
Returns: "0:46:21"
156
117
3863
2754
1755
Returns: "0:21:06"
6677
2462
9160
5715
8404
Returns: "1:15:43"
6762
2480
8097
7519
8045
Returns: "2:00:26"
1931
1689
8294
6252
3470
Returns: "0:47:38"
1944
822
6563
5797
2119
Returns: "0:15:43"
656
616
7348
6303
1553
Returns: "0:23:31"
4393
3099
9654
5036
6925
Returns: "1:08:23"
2839
2117
7426
7140
3806
Returns: "0:51:06"
6259
3297
9183
6650
7796
Returns: "1:22:07"
3792
1691
8397
6070
7368
Returns: "1:21:59"
1781
1376
9913
8999
4466
Returns: "1:02:41"
3278
2020
7923
6401
7850
Returns: "1:45:24"
4700
2061
7499
6518
5176
Returns: "0:43:34"
800
118
5000
906
1500
Returns: "0:03:57"
100
17
10000
4500
9000
Returns: "1:06:00"
1000
299
10000
2360
5000
Returns: "0:21:07"
400
65
1600
350
800
Returns: "0:02:30"
156
117
3863
2754
1755
Returns: "0:21:06"
1600
299
10000
2360
5200
Returns: "0:18:49"
1600
299
10000
2360
5000
Returns: "0:18:00"