Answered step by step
Verified Expert Solution
Link Copied!

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 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
Tester :
import java.util.Arrays;
/**
* Tester for the Orchard class.
*
* @author Qi Yang
* @version 2022-11-15
*/
public class OrchardTester
{
public static void main(String[] args)
{
Orchard trees = new Orchard(7);
trees.add(new Tree("lemon",12),0);
trees.add(new Tree("apricot",20),0);
trees.add(new Tree("cherry",13),2);
trees.add(new Tree("peach",10),1);
trees.add(new Tree("apple",20),4);
System.out.println(trees.treeList());
System.out.println("Expected: [apricot, peach, lemon, cherry, apple]");
System.out.println(trees.contains("cherry"));
System.out.println("Expected: true");
System.out.println(trees.contains("walnut"));
System.out.println("Expected: false");
System.out.println(trees.lastTallTree());
System.out.println("Expected: null");
trees.sort();
System.out.println(trees.treeList());
System.out.println("Expected: [peach, lemon, cherry, apple, apricot]");
trees.add(new Tree("walnut",35),1);
System.out.println(trees.treeList());
System.out.println("Expected: [peach, walnut, lemon, cherry, apple, apricot]");
System.out.println(trees.contains("walnut"));
System.out.println("Expected: true");
System.out.println(trees.lastTallTree());
System.out.println("Expected: Tree[Type:walnut,Height:35]");
trees.add(new Tree("avocado",35),-1);
trees.add(new Tree("avocado",35),7);
System.out.println(trees.treeList());
System.out.println("Expected: [peach, walnut, lemon, cherry, apple, apricot]");
trees.add(new Tree("avocado",35),6);
System.out.println(trees.treeList());
System.out.println("Expected: [peach, walnut, lemon, cherry, apple, apricot, avocado]");
System.out.println(trees.lastTallTree());
System.out.println("Expected: Tree[Type:avocado,Height:35]");
trees.sort();
System.out.println(trees.treeList());
System.out.println("Expected: [peach, lemon, cherry, apple, apricot, avocado, walnut]");
System.out.println(trees.lastTallTree());
System.out.println("Expected: Tree[Type:walnut,Height:35]");
trees.add(new Tree("olive",25),0);
System.out.println(trees.treeList());
System.out.println("Expected: [peach, lemon, cherry, apple, apricot, avocado, walnut]");
}
}
Using Bluej
image text in transcribed

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

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

What requirement did Health Canada initially require of Aurora?

Answered: 1 week ago