Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Goal: In this problem, you will revisit Tree and Orchard classes from Homework 1 2 Problem 1 2 B and implement a few updates as
Goal:
In this problem, you will revisit Tree and Orchard classes from Homework Problem B and
implement a few updates as follows:
The Height parameter in the Tree class is now an int instead of a double.
The Tree class implements the Comparable interface a tree comes first if its short, or its type
is smaller when its height is the same as another tree.
The Orchard class uses an array instead of an ArrayList to keep track of Tree objects.
Instructions:
Start a new BlueJ project called hwc in the csahomeworkhw folder. In the BlueJ project, create
a class called OrchardTester and copy over the code provided on Canvas. Next, create two classes
called Orchard and Tree the starter code provided for this example is the code you wrote from
Homework
Modify the Tree and Orchard classes using the updates listed above.
The Orchard should have the following methods:
add
Adds a tree at a given position of the array if the array is not full and the index is valid. It
does not do anything otherwise.
lastTallTree
Returns the last tree with a height at of at least or null if there is no such tree. The
method should stop execution and return the last tall tree after it is found.
contains
Determine if the array contains a Tree object of a given type. It returns either true or false.
treeList
Returns an ArrayList containing the types of all Tree objects in the array.
sort
Sort the array by calling a static method of class Arrays.
In addition, add an argument to the Orchard constructor to ingest the size of the array.
Tips and Guidelines:
Call the static method to sort.
Observe the behavior of the OrchardTester script to determine the action of the Tree and
Orchard classes.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started