// Forest.java
// Author: Kiri Wagstaff
// Date: July 24, 2001

public class Forest
{
    public static void main(String[] args)
    {
	Tree[] forest = new Tree[7];
		
	// Fill the forest with trees
	// and print it out
	for (int i=0; i<forest.length; i++)
	{
	    forest[i] = new Tree(Math.random()*5);		
	    System.out.println(forest[i] + " [" + forest[i].getClass() + "]");
	}
		
	System.out.println();
	// Now replace some of them with Conifers and some with Deciduous trees.
	for (int i=0; i<forest.length; i++)
	{
	    if (i%2 == 0)
	    {
		forest[i] = new Conifer(Math.random()*5, 
					(int)(Math.random()*100),
					(int)(Math.random()*20));
	    }
	    else if (i%3 == 0)
	    {
		forest[i] = new Deciduous(Math.random()*5,
					  (int)(Math.random()*100),
					  "green");
	    }
	    System.out.println(forest[i] + " [" + forest[i].getClass() + "]");
	}
			
	System.out.println();
	SavitchIn.read();

	System.out.println("Water all of the trees:");
	for (int i=0; i<forest.length; i++)
	{
	    forest[i].water();
	    System.out.println(forest[i]);
	}

	System.out.println();
	System.out.println("Get some cones:");
	for (int i=0; i<forest.length; i++)
	{
	    if (i%2 == 0) 
	    {
		// If it's a conifer, we can get a pinecone 
		// but we have to cast it back from a Tree
		// to a Conifer.  This will fail if we try
		// to cast the Deciduous trees to Conifers.
		Conifer c = (Conifer)forest[i];
		c.getCone();
	    }
	    System.out.println(forest[i]);
	}
	System.out.println();
		
	System.out.println("Winter falls:");
	for (int i=0; i<forest.length; i++)
	{
	    if (i%2 != 0 && i%3 == 0) 
	    {
		Deciduous d = (Deciduous)forest[i];
		d.setSeason("winter");
	    }
	    System.out.println(forest[i]);
	}
    }
}
