Problem Statement
| | | | |___ ___| |XXXXXXXXXXXXXX| | | |XXXXXX| | | |XXXXXX| |XXXXXX| |XXXXXX| |XXXXXX| |XXXXXX| (not flooded) (flooded)The amount of evaporation depends on the surface area. When the lake is not flooded, the evaporation is evapNormal units of water per day. When the lake is flooded, the evaporation is evapFlood units per day. The lake never goes dry and never extends beyond the floodplain.
Assume that the lake is initially full but not flooded. Create a class WaterLevel
that contains a method netAmt that is given evapNormal, evapFlood, and
Definition
- Class:
- WaterLevel
- Method:
- netAmt
- Parameters:
- int, int, int[]
- Returns:
- double
- Method signature:
- double netAmt(int evapNormal, int evapFlood, int[] rain)
- (be sure your method is public)
Notes
- A return value with either an absolute or relative error of less than 1.0E-9 is considered correct.
Constraints
- evapNormal will be between 0 and 1000 inclusive
- evapFlood will be between evapNormal and 1000 inclusive
- rain will contain between 1 and 50 elements inclusive
- each element of rain will be between 0 and 1000 inclusive
Examples
20
40
{0,60,0,0}
Returns: -35.0
After the first day, 20 units have evaporated so we are 20 units below flood stage. After the first half of the second day, 30 units of rain have fallen while 10 units have evaporated, so we have reached flood stage. By the end of the day another 30 have fallen and 20 (40 / 2) have evaporated leaving us 10 units above flood stage. On the third day, we leave flood stage after 1/4 of a day. By the end of the day we are 15 units below flood stage. On the fourth day 20 units evaporate leaving us 35 units below flood stage.
20
39
{0,60}
Returns: 10.5
After the first day, we are 20 units below flood stage. We reach flood stage after half of the next day. During the last half of the day 30 units of rain fall while 19.5 units evaporate.
20
40
{0}
Returns: -20.0
20
40
{1}
Returns: -19.0
287
912
{1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0}
Returns: -14125.0
20
40
{30,40,20,0}
Returns: -20.0
200
800
{0,600}
Returns: 0.0
After the first day, the level is 200 below flood stage due to evaporation. Halfway through the second day, 300 units have rain have fallen and 100 units have evaporated so we have just reached flood stage. After that we are at a stable equilibrium in which the level does not change.
100
212
{0,230,0,0,0,0,0,0}
Returns: -598.0406386066763
100
212
{0,200,200,200,200,213}
Returns: 1.0
150
150
{150,150,150,150,140,162,0}
Returns: -148.0
100
900
{0,800,3,1000}
Returns: 89.22222222222223
300
379
{0,800,0,800,512,555,1000}
Returns: 1210.6370448548812
200
300
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
Returns: -2880.0
300
400
{322,389,400,400}
Returns: 0.0
0
3
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
Returns: 0.0
0
37
{0,0,0,50,0,0,0,0}
Returns: 0.0
200
800
{ 0, 600 }
Returns: 0.0
17
35
{ 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 861 }
Returns: 577.0584174737277
1
2
{ 3 }
Returns: 1.0
20
40
{ 30, 0, 60, 0, 0, 13, 43, 21, 19 }
Returns: -19.0
0
10
{ 5 }
Returns: 0.0
0
200
{ 1 }
Returns: 0.0
100
200
{ 1, 2, 3, 4 }
Returns: -390.0
123
689
{ 0, 600, 600, 0, 0, 0, 0, 687, 364, 357, 0, 0, 0, 0, 453, 876, 754, 243, 159, 955, 466, 955, 955, 957, 0, 0, 0, 0, 0, 0, 0, 345, 786, 921, 783 }
Returns: 351.5289980232352
10
100
{ 10, 100, 100, 100, 1000, 10, 1, 0, 1, 1, 21, 100, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 10, 100, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000 }
Returns: 32644.0
10
100
{ 10, 100, 100, 10, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1, 1000, 1000, 1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1, 1, 1, 1, 1, 1, 1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000 }
Returns: 32409.0
20
40
{ 0 }
Returns: -20.0