PHW8: Forest

In class we saw how to compose objects to create a BoxCar class, and in PHW6 you created a Tree class. Now we’re going to create another composite shape: Forest.

Rx: <25 min Av: 25-50 min Sd: 50-75 min DNF: 75+ min

Instructions

  1. If you haven’t been following along in class, download the Picture Project and import it into your workspace.
  2. Create a new Forest class with:
    • Fields: at least 3 Trees (using a Collection such as ArrayList recommended). When drawn, the trees should overlap a little bit. For example:
    • A constructor with 4 parameters: x, y, width, & height. The width & height represent the overall width & height of the forest, not an individual tree.
    • A paint method that has a Graphics parameter and calls the corresponding draw methods for the trees.
  3. Test your new Forest class by replacing your Tree field(s) in the Picture class.
  4. Modify the position & sizes in the Picture class to change the look of your forest(s). Look at how easy it is to aggregate (i.e., reuse) components!