Question: Exercise 1 This exercise requires creating a class with variables, a constructor and methods. Additionally, you will use arrays, control statements, abstraction and inheritance. To
Exercise 1 This exercise requires creating a class with variables, a constructor and methods. Additionally, you will use arrays, control statements, abstraction and inheritance. To avoid naming conflicts place all of the classes in a package, e.g. ex1. The goal of this exercise is to create classes to print ASCII symbols that resemble trees. Each tree will be composed of a number of segments, and trees will be printed out by printing the segments on top of each other. Exercise 1A ] Create classes Tree, BroadleafTree, PineTree, Forest and MainEx1. The latter should have a main() method. Exercise 1B Make the Tree class abstract. The Tree class should have one private variable of type int that contains the height of the tree (in lines). This variable should be initialized via the constructor. Add a method called getHeight() that returns the height. Add an abstract method called getSegment() that returns a String. Exercise 1C Implement Bamboo, Broadleaf and Pine. These classes should inherit from Tree. The only method you should override is the abstract method getSegment(). This method should return a String containing the current segment. If height is n the heighest segment should be either n or n-1 (representing the tip of the tree) and the lowest should be 1 or 0 (representing the root of the tree). Either way there should be n possible segments that can be retrieved. Override the toString() method in Tree. This should return a String containing all n segments of the tree, one per line. For example Bamboo with height = 2 could look like this:with height = 5:a Pine with height=5:and a broadleaf with height=4:The graphical design (i.e. the symbols you return via getSegment()) of your tree is up to you. They should not be random and not all identical.Exercise 1D Implement Forest. The constructor of Forest should receive an int that defines the number of trees in the forest and an int that defines the maximum size. Choose the tree type (from the three tree classes) and height (within the specified range) randomly for every tree. Override the toString() method to print the Forest. All the trees should be next to each other and start at the same level. For example a Forest with five trees with maximum height eight: and of size 20 with maximum height 10 (note that trees can hava a size of zero):Exercise 1E Instantiate a Forest in your main method and print it to the command line.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
