/*
 * NamedSortableBunny class: add yet another method, compareTo in order to implement Comparable interface.
 * 
 * Lecture 22, Tue Mar 30 2006
 */
public class NamedSortableBunny implements Comparable
{
    private int x;
    private int y;
    private int numCarrots;
    private String name;
 
    // can we just say they have to pass in a namedsortablebunny? No, since the
    // compareTo method signature expects an Object.
    /*    
    public int compareTo(NamedSortableBunny other) 
    {
        return this.name.compareTo( other.getName());
    }
    */
    
    /**
     * Compare a Bunny based on its name. Note that we're doing something
     * dangerous here - we're simply assuming the object passed in is of the
     * correct type!
     */
    public int compareTo(Object other) 
    {
        //System.out.println("made it inside compareTo for bunnies");
        // debugging statement, to diagnose that this version of the method
        // wasn't being entered when we had a problem in our driver.
        // (we forgot to actually load our new objects into the bunnies array!)
 
        return this.name.compareTo( ( (NamedSortableBunny) other ).getName() );
    }
   
    /** 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 NamedSortableBunny(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");
    }
 
}

