/*
 * NamedBunny class: we further adapted the NamedBunny class from last
 * time to have toString and getName methods.
 * Lecture 19, Thu Mar 16 2006
 */
public class NamedBunny
{
    private int x;
    private int y;
    private int numCarrots;
    private String name;
 
    /** Return the Bunny's name */
    public String getName() {
        return name;
    }
    
    /** Return the state of the Bunny as one long string */
    public String toString() {
        return "x position "+x+" y position "+y+" numCarrots "
        +numCarrots+" name "+name;
    }
    
    public NamedBunny(int x, int y, int numCarrots, String name) 
    {
        this.x = x;
        this.y = y;
        this.numCarrots = numCarrots;
        this.name = name;
    }


    public void hop(int direction) {
        if (numCarrots > 0)    {
            System.out.println("hop");
            if (direction == 12)
                y++;
            else if (direction == 3) 
		x++;
	    else if (direction == 6) 
		y--;
	    else 
		x--;
            numCarrots--;
        } else {
            System.out.println("This bunny can't hop");
        }
    }
    
    public void displayInfo()
    {
        System.out.println("This bunny is at position "+x+","+y);
        System.out.println("This bunny has "+numCarrots+" carrots remaining");
    }
 
    public static void main( String[] args )
    {
        System.out.println("Testing Peter");
        NamedBunny peter = new NamedBunny(3,6,1,"Peter");
        peter.displayInfo();
        peter.hop(12);
        peter.hop(12);
        peter.hop(9);
        peter.displayInfo();
        System.out.println("Testing Emily");
        NamedBunny emily = new NamedBunny(3,4,5,"Emily");
        emily.displayInfo();
        emily.hop(9);
        emily.hop(9);
        emily.hop(9);
        emily.hop(12);
        emily.hop(9);
        emily.hop(12);
        emily.displayInfo();

    }

}

