// Deciduous.java // Author: Kiri Wagstaff // Date: July 24, 2001 public class Deciduous extends Tree { int numLeaves; String leafColor; public Deciduous() { // Because there is a default constructor for Tree, // we don't need to explictly call one here. // But we will anyway, to show how it's done. super(); numLeaves = 0; leafColor = null; } public Deciduous(double height, int numLeaves, String color) { // We need to specify which constructor we want here super(height); this.numLeaves = numLeaves; this.leafColor = color; } // Changing the season changes the color public void setSeason(String season) { if (season.equals("winter")) leafColor = "white"; else if (season.equals("spring")) leafColor = "light green"; else if (season.equals("summer")) leafColor = "green"; else /* fall */ leafColor = "red"; } // Override the Tree water() method public void water() { // Grow some leaves too! System.out.print(" (water leaves) "); numLeaves += 10; } public String toString() { // Call the superclass's method String s = super.toString(); // Now add some conifer-specific stuff return s + ", " + numLeaves + " " + leafColor + " leaves."; } }