Statistics

Problem Statement for "Buoyancy"

Problem Statement

An object can float only if it is less dense than water. A floating object displaces an amount of water equal to its weight. We are given an object (that may or may not float) and a container of water and we want to calculate the water level that will result when we place the object in the container. All weights are given in grams, all lengths are given in centimeters, and a cubic centimeter of water weighs one gram.

The container is a tall rectangular box (with no top) with horizontal dimensions wid x len. It is originally filled with water to a height of waterHt. The object is a rectangular solid that is 1 x 1 x objHt. The weight of the object is objWt. When placed in the water, the object remains upright whether it floats or rests on the bottom.

Create a class Buoyancy that contains a method waterLevel that is given wid, len, waterHt, objWt, and objHt and that returns the height of the water after the object has been placed in the container.

Definition

Class:
Buoyancy
Method:
waterLevel
Parameters:
double, double, double, double, double
Returns:
double
Method signature:
double waterLevel(double wid, double len, double waterHt, double objWt, double objHt)
(be sure your method is public)

Notes

  • The returned value must be accurate to within a relative or absolute value of 1E-9

Constraints

  • wid and len will be between 1.2 and 10.0 inclusive.
  • waterHt, objWt, and objHt will be between 0.1 and 500.0 inclusive.

Examples

  1. 2

    2

    100

    150

    80

    Returns: 120.0

    The object ends up on the bottom of the container, completely submerged. The final height of the water must be 120 since the total volume of the water and submerged object is 2*2*100 + 80 and that is equal to the new water level times the container's cross-section, 120*2*2.

  2. 2

    2

    100

    150

    140

    Returns: 133.33333333333334

    This object also sinks, but does not get completely submerged. In the final situation, the total volume of the water and the part of the object that is submerged is 2*2*100 + 1*1*133.33 and that is equal to 2*2*133.3.

  3. 2

    2

    100

    10

    160

    Returns: 102.5

    This object is very buoyant. It floats, with 10 units of its length submerged, displacing 10 grams of water. The total volume of the water and the submerged part of the object is then 2*2*100 + 10 and that is equal to 2*2*102.5.

  4. 1.2

    1.2

    35

    99

    99

    Returns: 103.75

  5. 1.2

    1.2

    35

    99

    98

    Returns: 103.05555555555556

  6. 1.2

    1.2

    500

    499

    500

    Returns: 846.5277777777778

  7. 1.2

    1.2

    500

    500

    500

    Returns: 847.2222222222222

  8. 2

    2

    500

    .1

    500

    Returns: 500.025

  9. 7

    1.3

    4

    8

    9

    Returns: 4.493827160493828

  10. 10

    10

    .1

    5

    2

    Returns: 0.10101010101010101

  11. 6

    2

    45

    89

    21

    Returns: 46.75

  12. 1.2

    1.2

    67

    32

    89

    Returns: 89.22222222222223

  13. 1.5

    9.5

    100

    3

    3.1

    Returns: 100.21052631578948

  14. 2

    2

    10

    9

    8

    Returns: 12.0

  15. 2

    2

    10

    8.00001

    8

    Returns: 12.0

  16. 2

    2

    10

    7.999996

    8

    Returns: 11.999999

  17. 2.0

    2.0

    50.0

    52.0

    60.0

    Returns: 63.0


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: