Write a new class called FertilisedTree, which is a more specialized version of the Tree class defined in Chapter 3, and modified in Exercise 3.14. A FertilisedTree differs from a Tree only in the way it grows. In the case of a FertilisedTree, when the height of the tree is greater than 1 metre, the growth rate decreases by 5% (as opposed to 10% in the case of a Tree). Only when a FertilisedTree reaches a height of 3 metres or more, does the growth rate decrease by 10%. Write a main method which creates one Tree and one FertilisedTree object, both with an initial height of 0.1 metres and growth rate of 20 cm/year. Allow both trees to grow for 30 years. Print out the height of both trees after the 30 years. (Hint: to access the height and rate attributes of Tree, change them to have protected access in class Tree.)
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here