Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program intended to track an arboretum: Tree: Contains three instance variables for ID number, age, and species name Implements a parameterized constructor

Write a Java program intended to track an arboretum:

Tree:

Contains three instance variables for ID number, age, and species name

Implements a parameterized constructor that will create a Tree object, and sets the aforementioned variables

Grove: Contains two instance variables for an Array of Tree's (size 8), and a grove name. You may use an ArrayList of Tree's if you wish

Implements a parameterized constructor that takes (and sets) a single parameter for the name of the grove

Implements a method that will plant a Tree object in the first available spot. The method should take a Tree object as a parameter, and return an int identifying the spot where the tree is planted. If no spots are open, return -1.

Implements a method that will remove a Tree object from a given spot. The method should take an int as a parameter, and remove and return the Tree object at that location in the array.

Implement a ToString() method that will print a single int representing the number of Tree's in the array

GroveTester:

Implement a main() function that will carry out the following instructions:

Instantiate a grove object named Grove One Print the grove object named Grove One

Instantiate seven Tree objects of species Pine and age 37, and add them to Grove One

Print the grove object named Grove One

Remove the Tree's from Grove One at index 3 and 5.

Print the grove object named Grove One

Instantiate one Tree object of species Spruce and age 13, and add it to Grove One

Print the grove object named Grove One

Note: A grove's name and a variable name that contains it are two different things! You should store the grove name as a string.

Expected Output:

0

7

5

6

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

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions

Question

13.1 Explain the strategic role of employee benefits.

Answered: 1 week ago