Project: Water Catchment Systems (Java)

Water Catchment Systems

Water catchment systems are a critical source of water in many parts of the world. These systems collect rainwater and distribute it to a house, lodging, or neighborhood using a series of gravity-propelled plumbing. Such systems can also act as a reservoir by which local populations can “fill up” containers and transport the water to other locations. The following video provides a brief description of these benefits and how to create a water catchment system:

Assume we have a full water catchment tank, shaped like a cylinder. How long would it take to empty that cylinder, if we “unscrewed” an output nozzle on the bottom? Determining the rate at which the cylinder would empty out would require knowledge of the height of the tank, the radius of the tank, and the radius of the output nozzle. Once we had this knowledge, we could apply a few simple math equations to get an approximate answer. This information would be helpful to measure the amount of water that would be used for various household uses (e.g. showers).

Java Project: Emptying Water Catchment Tanks

This project will provide you with an introduction to the fundamentals of conditional repetition in Java. The focus of this project is on how to solve problems using the Java “while” or “do-while” statements. In this project, you will…

  • Develop code to read data from the standard input and produce data to the standard output.
  • Write code that conforms to a programming style specified by the instructor.
  • Translate given mathematical expressions into equivalent syntactically correct programming statements.
  • Select and implement the appropriate conditional repetition control structure(s) for this problem.

As always, be sure to properly document your code. Consult the Java Coding Guidelines document for proper coding standards. Use good design principles and design the solution before attempting to write code.

Create a Java class called WaterCatchment.java. This program will simulate the draining of a cylindrical water catchment tank. Your program inputs are as follows:

  • The height of the cylindrical tank, in inches (a double value, 72-240 inches)
  • The radius of the cylindrical tank, in inches (a double value, 2-36 inches)
  • The number of time steps, in seconds (an int value, 1-100)

Note that the values above will be input from the user only once.

Once the input is finished, your program will display the initial volume (in cubic inches), the time elapsed (in seconds), the volume lost at that time step (in cubic inches), and the height of the water in the catchment tank at that time step (in inches).

Assuming a constant flow, the volume of water in the tank will decrease to zero over time (i.e. the tank will be empty). You should assume the tank is initially full with water. Here are some formulas you will find useful:

  • Initial Volume of a Cylinder (i.e. the water tank): V = πr2h
  • Velocity of Outward Flow Through the Nozzle: velocity = 8.02 * (current height of the water in the tank)
  • Volume Lost From a Cylinder At Time t: Volume Lost = velocity * (4π) * t
  • Height of Water in the Cylindrical Tank at Time t: h = (current volume at time t) / (πr2)

Your code should update the values each time through the loop. The loop should start at time zero and end when either the user-defined number of time steps has been reached or the water catchment tank runs dry (i.e. volume of water in the tank is ≤ 0).

Note that you will first need to calculate the volume of the cylinder when it is full (the initial volume), and output it to the screen. After this point, your code should enter a conditional repetition structure (a loop) to simulate the time steps. For each time step (i.e., each time through the loop), you will first need to calculate the velocity of flow. Once the velocity is calculated, you then need to calculate the volume lost during this time step. The volume lost is then subtracted from that current volume (in the first loop iteration, this is the initial or “full” volume). Afterwards, the new height of the water can be calculated from this “new” current volume. When the volume in the tank reaches zero (or less) OR you have completed your user-defined number of time steps, your program should stop its calculations. Your program may use 3.14159265 as the value of PI (π) for testing purposes.

The following partial flowchart depicts the logic used for the loop and its iterations. The flowchart assumes input has already been performed, and all variables have been initialized appropriately:

WaterCatchmentFlowchart

All numerical values should be precise to two decimal places. Here are few sample tests you can run to check if your program is working correctly:

Test Case #1

Enter the height of the cylindrical tank, in inches: 240
Enter the radius of the cylindrical tank, in inches: 12
Enter the number of time steps, in seconds: 5

The initial volume is 108573.44 cubic inches.
After 5 second(s):
   The volume lost at this time step is 7238.85 cubic inches. 
   The water height at this time step is 190.36 inches.

Test Case #2

Enter the height of the cylindrical tank, in inches: 84
Enter the radius of the cylindrical tank, in inches: 2.5
Enter the number of time steps, in seconds: 5

The initial volume is 1649.34 cubic inches.
After 5 second(s):
   The water catchment tank is empty.

Test Case #3

Enter the height of the cylindrical tank, in inches: 72
Enter the radius of the cylindrical tank, in inches: 8
Enter the number of time steps, in seconds: 1

The initial volume is 14476.46 cubic inches.
After 1 second(s):
   The volume lost at this time step is 855.17 cubic inches. 
   The water height at this time step is 67.75 inches.

Test Case #4

Enter the height of the cylindrical tank, in inches: 36
ERROR: The height must be in the range [72-240]. Please try again.

Enter the height of the cylindrical tank, in inches: 128
Enter the radius of the cylindrical tank, in inches: 40
ERROR: The radius must be in the range [2-36]. Please try again.

Enter the radius of the cylindrical tank, in inches: 22
Enter the number of time steps, in seconds: 0
ERROR: The number of time steps must be in the range [1-100]. Please try again.

Enter the number of time steps, in seconds: 18

The initial volume is 194627.95 cubic inches.
After 18 second(s):
   The volume lost at this time step is 11096.54 cubic inches. 
   The water height at this time step is 30.12 inches.

Deliverables

See the instructor for submission instructions and due date(s).

Powered by WordPress. Designed by WooThemes

Skip to toolbar