Project: Tree Growth (Version 3)

Trees and Growth Patterns

Trees provide a number of benefits for the environment. Trees are able to absorb dangerous gases such as carbon dioxide (CO2) while, at the same time, producing oxygen for us to breathe. Trees also absorb and distribute water that otherwise may lead to runoff, thus reducing pollution and loss of topsoil. Some forms of trees even produce food for us to eat (think: apple trees). Watch the following animated video to learn more about the benefits of trees to our society:

As we plant trees strategically, we often want to know how tall a tree can be expected to grow. While there are environmental factors that impact tree growth patterns, we can approximate the height of tree if we know certain facts. As trees grow, they add approximately the same amount of mass each year. If we know this amount, we can compute the expected height of a tree over time. The height of a tree (h) can be approximated based on its age using the following formula:

Tree_Growth_Equation

where a = the amount of mass added to a tree each year and t is the age in years.

Tree02

 

Java Project: Computing Tree Growth

This project will provide you with an introduction to the fundamentals of problem-solving in Java. The focus of this project is on how to solve simple problems using Java classes, primitive data types, variables, for loops, functions, one-dimensional arrays, and arithmetic operations. In this project, you will…

  • Develop code to read data from the standard input and produce data to the standard output.
  • Translate a given mathematical expression into equivalent syntactically correct programming statements.
  • Write code that conforms to a programming style specified by the instructor.
  • Select and implement the appropriate control structure(s) for this problem.
  • Decompose the problem into a sequence of single-purpose methods.
  • Declare, define, and initialize one-dimensional, simple data type arrays of a fixed size.
  • Demonstrate the ability to read from and write to an arbitrary array element using array indices.
  • Demonstrate an ability to process the entire array, one element at a time, performing both read and write operations.

Create a Java class called TreeGrowth.java to compute the approximate height of a tree based on the amount of mass added each year (a double value) and the age in years (an int value). Once the input is received and echo-printed to the screen, use a for loop to compute the height for the present age and the next 9 years. Each height should be stored into one element of a one-dimensional array or ArrayList object.

Only after the entire set of computations is complete (i.e. when the for loop mentioned above is complete), use another for loop to output the contents of the one-dimensional array or ArrayList object to the screen, with descriptive messages. All floating-point numeric amounts should be precise to two decimal places.

Be sure that your class is decomposed into static methods (2 input methods, 1-2 computation methods, and 1-2 output methods). Remember to validate the inputs (> 0). Here are few sample tests you can run to check if your “run” is working correctly:

Test Case #1

Enter the Amount of Mass: 256.0
Enter the Age in Years: 81
You entered a mass of 256.00 and an age of 81 years.

At age 81 years, the approximate height of the tree is 12.00 meters.
At age 82 years, the approximate height of the tree is 12.04 meters.
At age 83 years, the approximate height of the tree is 12.07 meters.
At age 84 years, the approximate height of the tree is 12.11 meters.
At age 85 years, the approximate height of the tree is 12.15 meters.
At age 86 years, the approximate height of the tree is 12.18 meters.
At age 87 years, the approximate height of the tree is 12.22 meters.
At age 88 years, the approximate height of the tree is 12.25 meters.
At age 89 years, the approximate height of the tree is 12.29 meters.
At age 90 years, the approximate height of the tree is 12.32 meters.

Test Case #2

Enter the Amount of Mass: 5333.3333
Enter the Age in Years: 30
You entered a mass of 5333.33 and an age of 30 years.

At age 30 years, the approximate height of the tree is 20.00 meters.
At age 31 years, the approximate height of the tree is 20.16 meters.
At age 32 years, the approximate height of the tree is 20.33 meters.
At age 33 years, the approximate height of the tree is 20.48 meters.
At age 34 years, the approximate height of the tree is 20.64 meters.
At age 35 years, the approximate height of the tree is 20.79 meters.
At age 36 years, the approximate height of the tree is 20.93 meters.
At age 37 years, the approximate height of the tree is 21.08 meters.
At age 38 years, the approximate height of the tree is 21.22 meters.
At age 39 years, the approximate height of the tree is 21.36 meters.

Test Case #3

Enter the Amount of Mass: 2000.50
Enter the Age in Years: 123
You entered a mass of 2000.50 and an age of 123 years.

At age 123 years, the approximate height of the tree is 22.27 meters.
At age 124 years, the approximate height of the tree is 22.32 meters.
At age 125 years, the approximate height of the tree is 22.36 meters.
At age 126 years, the approximate height of the tree is 22.41 meters.
At age 127 years, the approximate height of the tree is 22.45 meters.
At age 128 years, the approximate height of the tree is 22.50 meters.
At age 129 years, the approximate height of the tree is 22.54 meters.
At age 130 years, the approximate height of the tree is 22.58 meters.
At age 131 years, the approximate height of the tree is 22.63 meters.
At age 132 years, the approximate height of the tree is 22.67 meters.

Deliverables

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

Powered by WordPress. Designed by WooThemes

Skip to toolbar