Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Instructions: Start a new BlueJ project called hw 1 4 c in the cs 4 6 a / homework / hw 1 4 folder. In
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 Tester : import java.util.Arrays; Tester for the Orchard class. @author Qi Yang @version public class OrchardTester public static void mainString args Orchard trees new Orchard; trees.addnew Treelemon; trees.addnew Treeapricot; trees.addnew Treecherry; trees.addnew Treepeach; trees.addnew Treeapple; System.out.printlntreestreeList; System.out.printlnExpected: apricot peach, lemon, cherry, apple; System.out.printlntreescontainscherry; System.out.printlnExpected: true"; System.out.printlntreescontainswalnut; System.out.printlnExpected: false"; System.out.printlntreeslastTallTree; System.out.printlnExpected: null"; trees.sort; System.out.printlntreestreeList; System.out.printlnExpected: peach lemon, cherry, apple, apricot; trees.addnew Treewalnut; System.out.printlntreestreeList; System.out.printlnExpected: peach walnut, lemon, cherry, apple, apricot; System.out.printlntreescontainswalnut; System.out.printlnExpected: true"; System.out.printlntreeslastTallTree; System.out.printlnExpected: TreeType:walnut,Height:; trees.addnew Treeavocado; trees.addnew Treeavocado; System.out.printlntreestreeList; System.out.printlnExpected: peach walnut, lemon, cherry, apple, apricot; trees.addnew Treeavocado; System.out.printlntreestreeList; System.out.printlnExpected: peach walnut, lemon, cherry, apple, apricot, avocado; System.out.printlntreeslastTallTree; System.out.printlnExpected: TreeType:avocado,Height:; trees.sort; System.out.printlntreestreeList; System.out.printlnExpected: peach lemon, cherry, apple, apricot, avocado, walnut; System.out.printlntreeslastTallTree; System.out.printlnExpected: TreeType:walnut,Height:; trees.addnew Treeolive; System.out.printlntreestreeList; System.out.printlnExpected: peach lemon, cherry, apple, apricot, avocado, walnut; Using Bluej
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
Tester :
import java.util.Arrays;
Tester for the Orchard class.
@author Qi Yang
@version
public class OrchardTester
public static void mainString args
Orchard trees new Orchard;
trees.addnew Treelemon;
trees.addnew Treeapricot;
trees.addnew Treecherry;
trees.addnew Treepeach;
trees.addnew Treeapple;
System.out.printlntreestreeList;
System.out.printlnExpected: apricot peach, lemon, cherry, apple;
System.out.printlntreescontainscherry;
System.out.printlnExpected: true";
System.out.printlntreescontainswalnut;
System.out.printlnExpected: false";
System.out.printlntreeslastTallTree;
System.out.printlnExpected: null";
trees.sort;
System.out.printlntreestreeList;
System.out.printlnExpected: peach lemon, cherry, apple, apricot;
trees.addnew Treewalnut;
System.out.printlntreestreeList;
System.out.printlnExpected: peach walnut, lemon, cherry, apple, apricot;
System.out.printlntreescontainswalnut;
System.out.printlnExpected: true";
System.out.printlntreeslastTallTree;
System.out.printlnExpected: TreeType:walnut,Height:;
trees.addnew Treeavocado;
trees.addnew Treeavocado;
System.out.printlntreestreeList;
System.out.printlnExpected: peach walnut, lemon, cherry, apple, apricot;
trees.addnew Treeavocado;
System.out.printlntreestreeList;
System.out.printlnExpected: peach walnut, lemon, cherry, apple, apricot, avocado;
System.out.printlntreeslastTallTree;
System.out.printlnExpected: TreeType:avocado,Height:;
trees.sort;
System.out.printlntreestreeList;
System.out.printlnExpected: peach lemon, cherry, apple, apricot, avocado, walnut;
System.out.printlntreeslastTallTree;
System.out.printlnExpected: TreeType:walnut,Height:;
trees.addnew Treeolive;
System.out.printlntreestreeList;
System.out.printlnExpected: peach lemon, cherry, apple, apricot, avocado, walnut;
Using Bluej
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