Any topic (writer’s choice)
May 20, 2020
Reading Resource: Holly Sklar, Imagine A Country
May 20, 2020
Show all

class Exercise 01

Problem
Write Java class for a Tree class. This class must have methods to

default constructor
set and get the type (coniferous, deciduous, dead)
set and get the variety (for example apple, maple, etc.)
set and get the age
set and get the height
set and get the value
toString method that returns all of the tree information as a string
Remember you must guard against wrong values for type, age, and height.

Special Note: If you use an if statement to error check the type a string, you must use the equals string method not == or !=. Your tester program may appear to work using == or !=. However, the error checking will fail to work correctly when users input values for the type in a client program.

Example to test for a type not equal to dead use

!type.equals(“dead”)
do not use
type != “dead”
Create the Tree class.
Tesing the Tree class: Go to Testing Class Exercise 01
Submit Tree.java to the Blackboard Assignment: classexercise01

Leave a Reply

Your email address will not be published. Required fields are marked *