Java Project: Tree Growth

The United Nations (UN) has set forth 17 goals for sustainable development. Goal 15 is designed to “Sustainably manage forests, combat desertification, halt and reverse land degradation, halt biodiversity loss.” The effects of deforestation – both man-made and otherwise – can have a dramatic impact in a number of social, biological, and economic sectors. For example, many industries rely on trees or tree products as a fundamental component of their operations, whether it be for construction, paper, or agriculture.

Trees (and, consequently, forests) provide a number of benefits, but are a resource which takes time to replenish. In this project, we will consider the growth rate of trees.

Benefits of Trees

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) and provide habitat for many species. Watch the following animated video to learn more about the benefits of trees to our society. Though not Pennsylvania-specific, the concepts discussed in the video apply to Pennsylvania or any other temperate region:

Calculating the height of a tree over time can help determine which trees will best thrive in a specific environment, as tall-growing trees can stifle shorter trees if planted in close proximity. Tree heights can also help researchers determine such things as the likely bird inhabitants of a forest – species often prefer to nest in trees of a specific height, for example – as well as the animal life, level of stream shade, and ground vegetation of the underlying surface. Such information can be helpful for land development and management purposes: as trees compete for vital resources such as sunlight and water, computing such things as the height or the expected gain in mass over time can inform choices of which trees to plant for a sustainable ecosystem.

Where Can I Learn More?

Here are some links to additional information on this topic:

For this problem, you will compute the growth of a tree over time.


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 primitive data types, variables, for loops, 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.

As you write your code, be sure to properly document your code. Consult the Java Coding Guidelines document (provided by the instructor) for style expectations. Well-written code is easier to debug, easier to maintain over time, and easier to extend as new requirements arise.

Trees and Growth Patterns

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

Exercise #1: Create a class called TreeGrowth and save the file as TreeGrowth.java in your Java development environment. This program will ultimately compute the approximate height of a tree based on two inputs: the amount of mass added each year (a double value) and the age in years (an int value). As a first step, add code to your program which prompts the user for the two inputs and stores them in local variables. Once the input is complete, your program should echo-print the input values and end the program.

All floating-point output values should be precise to two decimal places. Validate both inputs to verify that they are greater than 0 (one validation loop for each input). Here are few sample tests you can run to check if your program is working correctly; your prompts should appear exactly as shown here, and you can type in the listed input values when prompted:

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.

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.

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.

Exercise #2: Next, you will add code to your program to produce a series of 10 output lines. This output will include the height for the present age and for the next 9 years, in sequential order. Hint: use a for loop.

Test Case #4

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 #5

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 #6

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.

Test Case #7

Enter the Amount of Mass: -10
ERROR: The mass must be > 0. Please try again.
Enter the Amount of Mass: 0
ERROR: The mass must be > 0. Please try again.
Enter the Amount of Mass: 256.0
Enter the Age in Years: -1
ERROR: The age must be > 0. Please try again.
Enter the Age in Years: 0
ERROR: The age must be > 0. Please try again.
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.

Your program is now complete.

Deliverables

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

Powered by WordPress. Designed by WooThemes

Skip to toolbar