Java Project: Trees and Carbon

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 carbon absorption capacity 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 absorb carbon dioxide through photosynthesis. The amount of CO2 absorbed can grow over time, as a tree with greater mass can old a greater amount of carbon. This may be especially helpful for cities, where high amounts of air pollution often exist. The following video discusses why cities may be wise to plant more trees:

Where Can I Learn More?

Here are some links to additional information on this topic:

For this problem you will compute the carbon absorption capacity of trees.


Java Project: Computing The Benefits of Trees

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 primitive Java 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.
  • Declare, define, and initialize one-dimensional 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.

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 CO2 Absorption

Suppose we wanted to measure the amount of carbon absorbed by a cluster (group) of trees. In order to calculate the amount of carbon stored by a tree, we need to know a few facts about the tree. One thing we need to know is the diameter of the tree, measured at approximately 1.4 m (4.5 ft) above ground. This height is known as the diameter breast height. The other thing we need to know is the height of the tree, in centimeters (cm). We can use the diameter d and height h to compute the green weight mass (wood content + moisture) of the tree in kilograms (kg), as follows:

Diameter Formula
Less Than 28 cm    0.0577 x d2 × h
Greater Than or Equal To 28 cm    0.0346 x d2 × h

Once we have the green weight mass gw, we can use that mass to compute the amount of carbon stored by the tree, using this formula:

carbon = 0.25 * gw

Where carbon is the mass of carbon in kilograms (kg). Finally, we can approximate the amount of CO2 stored by the tree using this equivalency: 3.67 kg for every 1 kg of carbon stored. Now that we can approximate the amount of CO2 stored in a tree, let’s consider what that would mean for an entire forest.

Create a class called TreeBenefits.java in your Java development environment. This program will ultimately compute the approximate amount of CO2 absorbed by a cluster a trees. Your program should input a series of 10 pairs (a tree height and a tree diameter) representing measurements for 10 trees. Your must program must use a for loop to control the number of input pairs received, and you must use arrays to store the input values.

Once you have received the input, use the aforementioned formulas to produce  a table of values to the screen with five labeled columns, nicely formatted and spaced:

  • The height of the tree, in cm
  • The diameter of the tree, in cm
  • The green weight (mass)
  • The amount of carbon stored by the tree, in kg
  • The amount of CO2 stored by the tree, in kg

At the end of the table, you should also include a report of the total amount of CO2 absorbed by the tree, in kg. All floating-point output values should be precise to two decimal places. Validate the height input to verify it is greater than 30.48 cm and validate the diameter input to verify it is greater than 2.0 cm (you may use one validation loop for each input, or one loop for both inputs).

Here is a sample test 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. It is highly recommended that you test the program with multiple sets of your own data to ensure that it is working – the instructor will do the same:

Test Case

Enter the height <space> diameter, both in cm: 57.0 9.2
Enter the height <space> diameter, both in cm: 50.0 7.0
Enter the height <space> diameter, both in cm: 68.0 8.7
Enter the height <space> diameter, both in cm: 64.0 10.1
Enter the height <space> diameter, both in cm: 58.0 9.6
Enter the height <space> diameter, both in cm: 50.0 9.0
Enter the height <space> diameter, both in cm: 60.0 8.6
Enter the height <space> diameter, both in cm: 70.0 9.3
Enter the height <space> diameter, both in cm: 52.0 6.6
Enter the height <space> diameter, both in cm: 47.0 9.9

     HEIGHT   DIAMETER        MASS          CARBON           CO2
     ------   --------        ----          ------           ---
     57.00      9.20         278.37          69.59         255.41
     50.00      7.00         141.37          35.34         129.70
     68.00      8.70         296.98          74.24         272.48
     64.00     10.10         376.70          94.18         345.62
     58.00      9.60         308.42          77.11         282.98
     50.00      9.00         233.69          58.42         214.41
     60.00      8.60         256.05          64.01         234.93
     70.00      9.30         349.33          87.33         320.51
     52.00      6.60         130.70          32.67         119.91
     47.00      9.90         265.79          66.45         243.87

                        TOTAL CO2: 2419.81

Here is an example of the feedback the user should see if he/she enters an invalid value:

Enter the height <space> diameter, both in cm: 20.0 7.0
*** ERROR: The height must be greater than 30.48 cm. Please try again.

Enter the height <space> diameter, both in cm: 68.0 7.0
Enter the height <space> diameter, both in cm: 64.0 1.7
*** ERROR: The diameter must be greater than 2.0 cm. Please try again.

Enter the height <space> diameter, both in cm: 64.0 9.6
Enter the height <space> diameter, both in cm: 30.0 1.0
*** ERROR: The height must be greater than 30.48 cm. Please try again.
*** ERROR: The diameter must be greater than 2.0 cm. Please try again.

Enter the height <space> diameter, both in cm: 60.0 8.6
...

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