Project: Mango Growth Simulation

The goal of this project is to write a suit of classes for simulating the growth, maintenance, and harvesting of Mango trees.

The project is divided into two parts. The first part is to write the code for class Mango, which is designed for a Mango tree that grows and whose fruits appreciate overtime.

The second part is to write the code for class MangoSim, which conducts a simulation of growing various mango trees for a number of years, and produces information as to which mango tree will be the most profitable.

Class Mango

We envision that each Mango tree has the following field variables:

There should be a constructor that takes values for the kind the height, and the price as parameters and sets these to instance variables.

There should be methods for accessing the kind, the height, and the price: getKind(), getHeight(), and getPrice().

Each year the price appreciates by 1 percent.

Each year a tree grows in percentage ranging uniformly between 5 percent and 15 percent. After growing if the tree becomes too tall, since it will go beyond the reach of pickers, the tree is trimmed down to precisely 150 inches. The reach of pickers is 260 inches.

After the price and the height updates, fruits can be picked from the tree and sold. The amount harvested from a tree is two times the inches in height of the tree times the price.

There should be a method by the name of process() for executing the two updates and returns as boolean whether the tree has been trimmed, which should consist of two parts:

The latter method should return whether the tree has been trimmed.

There should also be a method by the name of getHarvest() for obtaining the number of fruits harvested from the tree according to its height.

The above idea has been defined in an interface MangoInterface.java. Your code should implement this interface.

Class MangoTest

This is not part of the entire scheme, but can be used to test whether the class Mango correctly implements MangoInterface.

A sample execution produces the following output:
% java MangoTest
Trimmed. kind=Alfonso, height=150, price=404, harvest=121200
Not trimmed. kind=Alfonso, height=171, price=408, harvest=139536
Not trimmed. kind=Alfonso, height=196, price=412, harvest=161504
Not trimmed. kind=Alfonso, height=217, price=416, harvest=180544
Not trimmed. kind=Alfonso, height=241, price=420, harvest=202440
Trimmed. kind=Alfonso, height=150, price=424, harvest=127200
Not trimmed. kind=Alfonso, height=158, price=428, harvest=135248
Not trimmed. kind=Alfonso, height=180, price=432, harvest=155520
Not trimmed. kind=Alfonso, height=195, price=436, harvest=170040
Not trimmed. kind=Alfonso, height=209, price=440, harvest=183920
Not trimmed. kind=Alfonso, height=235, price=444, harvest=208680
Not trimmed. kind=Alfonso, height=248, price=448, harvest=222208
Trimmed. kind=Alfonso, height=150, price=452, harvest=135600
Not trimmed. kind=Alfonso, height=170, price=456, harvest=155040
Not trimmed. kind=Alfonso, height=178, price=460, harvest=163760
Not trimmed. kind=Alfonso, height=196, price=464, harvest=181888
Not trimmed. kind=Alfonso, height=219, price=468, harvest=204984
Not trimmed. kind=Alfonso, height=232, price=472, harvest=219008
Not trimmed. kind=Alfonso, height=248, price=476, harvest=236096
Trimmed. kind=Alfonso, height=150, price=480, harvest=144000

Class MangoSim

For the second part, class MangoSim is an object class whose constructor takes no parameter. Using one of its field variables, an object of this class maintains an array of mangos. To this array of mangos, the growth simulation will be run. The class has the following instance methods:

Class MangoMain

This is the main class for running the simulation. The code is already written for this class. The class creates a MangoSim object and intersts with the user to take an appropriate action for each user's input.

This is the interface: MangoInterface.java

This is the simulation program: MangoSim.java

This is the test program MangoTest.java

Here is the main class MangoMain.java

Here is a demo execution of a completed program. Link

Go back to the lab main page

Go back to the home page