Answered step by step
Verified Expert Solution
Link Copied!

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 12 Problem 12B 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 hw14c in the cs46a/homework/hw14 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 10).
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 30 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions