Problem Statement
Due to historical reasons people measure temperature in different scales, such as Fahrenheit and Celsius. Your task is to convert a temperature from one scale to another. It is known that both scales are linear with respect to each other (i.e., there are real numbers a and b such that temperature t presented in the first scale can be converted to the second by the law t'=a*t+b).
You are given 5
Definition
- Class:
- TemperatureScales
- Method:
- convert
- Parameters:
- int, int, int, int, int
- Returns:
- double
- Method signature:
- double convert(int f1, int b1, int f2, int b2, int t)
- (be sure your method is public)
Notes
- The return value must be within 1e-9 absolute or relative error of the actual result.
- Because the boiling and the freezing points of water depend on the atmospheric pressure, you may assume that both the scales are under the same circumstances.
Constraints
- f1,b1,f2,b2 and t will each be between -1000 and 1000, inclusive.
- f1 will be less than b1.
- f2 will be less than b2.
Examples
0
100
0
100
28
Returns: 28.0
These are two identical scales, so temperatures in both of them coincide.
0
100
1
101
28
Returns: 29.0
The second scale is shifted up 1 degree relative to the first scale.
-1000
-999
-1000
1000
1000
Returns: 3999000.0
-10
0
1
2
17
Returns: 3.7
17
98
-123
12
22
Returns: -114.66666666666667
-507
239
-802
-469
-678
Returns: -878.3310991957104
341
537
-27
890
-412
Returns: -3549.964285714286
-462
977
-546
352
426
Returns: 8.151494093120222
-540
368
-59
313
-742
Returns: -141.75770925110132
-534
282
-688
948
-203
Returns: -24.377450980392158
-933
506
378
379
-820
Returns: 378.07852675469076
-431
-291
4
980
442
Returns: 6090.057142857143
213
561
-58
36
-115
Returns: -146.5977011494253
-523
698
515
756
-906
Returns: 439.4037674037674
-675
474
-395
417
-744
Returns: -443.76240208877283
-607
416
-556
219
88
Returns: -29.484848484848484
-934
-411
-462
281
788
Returns: 1984.359464627151
-94
412
-140
886
296
Returns: 650.7905138339921
-850
-258
7
637
-25
Returns: 884.956081081081
-853
241
671
963
-224
Returns: 838.8866544789762
181
970
-395
574
680
Returns: 217.8403041825095
-27
550
-443
-414
-52
Returns: -444.25649913344887
-530
-273
-356
841
131
Returns: 2722.6653696498056
-903
-138
-887
677
-290
Returns: 366.24444444444447
-394
-340
599
638
-931
Returns: 211.16666666666666
0
324
886
959
686
Returns: 1040.5617283950617
-395
853
-515
774
119
Returns: 15.886217948717949
-896
-456
-262
877
-677
Returns: 304.91136363636366
-218
905
-10
380
-719
Returns: -183.9893143365984
-783
321
-635
866
-644
Returns: -446.0153985507246
-10
0
1
2
17
Returns: 3.7
17
98
-123
12
22
Returns: -114.66666666666667
1
2
0
1
3
Returns: 2.0
0
100
0
100
28
Returns: 28.0
-1000
-999
-1000
1000
1000
Returns: 3999000.0
-20
20
-7
60
0
Returns: 26.5
-1000
1000
10
11
20
Returns: 10.51
50
150
750
950
23
Returns: 696.0
3
6
4
24
2
Returns: -2.6666666666666665
34
98
55
56
77
Returns: 55.671875
5
7
5
6
1
Returns: 3.0
-1000
-937
-1000
666
347
Returns: 34620.666666666664