import java.io.*;

class BeanFarmer {
    
    public static Stack pile;
    public static BufferedReader stdin;

    public static void main (String[] args) {
	
	stdin = new BufferedReader( new InputStreamReader( System.in ));

	System.out.println("Creating space for 6 beans on the pile..");
	pile = new Stack(6);

	System.out.println("Adding 4 beans..");
	addBeans(4);
	
	System.out.println("\nDisplaying the pile of beans..");
	displayPile();

	System.out.println("Counting for GREEN beans");
	int count = countBeans("GREEN");
	System.out.println("Found " + count + " bean(s)");

	System.out.println("\nRemoving the top two beans");
	removeBeans(2);

    }

    public static void addBeans(int count) {
	for (int i = 0; i < count; i++) {
	    int size = UserTalker.getInteger("What's the size " + 
					     "of bean " + i + "? ", stdin);
	    String color = UserTalker.getColor("What's the color " + 
					       "of bean " + i + "? ", stdin);
	    Bean b = new Bean(size, color);
	    if (! pile.contains(b)) {
		pile.push( b );
	    }
	    else {
		System.out.println("We already have a bean with " + b);
		i--;
	    }
	}
    }
    
    public static void displayPile() {
	System.out.println( pile );
    }

    public static int countBeans(String match) {
	int count = 0;
	for (int i = 0; i<pile.getTop() + 1; i++) {
	    Bean b = (Bean)pile.peek(i);
	    if ((b.getColor()).equals("GREEN")) {
		count++;
	    }
	}
	return count;
    }

    public static void removeBeans(int count) {
	for (int i = 0; i<count; i++) {
	    Object o = pile.pop();
	    System.out.println("Removing " + o);
	}
    }
}

