/** 
 * @author CPSC 111 class and Tamara Munzner
 * @date Wed Mar 31
 *
 * Extend Bunny class to support names and initial x/y/carrot settings.
 */
public class NamedBunny {
	private int x,y,carrots;
	String name;

	// constructor should be public not private
	// don't want a void return type for a constructor, because you'd toss away all your work
	public NamedBunny() {
		// can we say x vs this.x here? yes, ok just say x here, no other variable named x in our scope.
		x = 10;
		y = 10;
		carrots = 5;
		name = "Google";
	}
	public NamedBunny(int x, int y, int carrots, String name) {
		// now that we have a parameter x in our scope, we must use "this.x" to mean the class field
		this.x = x;
		this.y = y;
		this.carrots = carrots;
		this.name = name;
	}

	public String getName() {
		return name;
	}
	public void hop(int direction) {
		// no, don't need for loops here! just need to change location according to parameter
		//for (int i = 0; i < 10; i++) {
		//for (int j = 0; j < 10; j++) {
		// ran out of time here!
		if (carrots <= 0) {
			System.out.println("This bunny can't hop");
			return;
		}
		// would also be legal to test as we go
		// or to have an if/else statement
		if (direction == 12) {
			y++;
			carrots--;
			System.out.println("hop");
		} else if (direction == 9) {
			x--;
			carrots--;
			System.out.println("hop");
		} else if (direction == 6) {
			y--;
			carrots--;
			System.out.println("hop");
		} else if (direction == 3) {
			x++;
			carrots--;
			System.out.println("hop");
		}
		// carrots--; // if we decrement carrots here, we'd use up energy even for garbage input. so let's move this to inside the conditional

	}
	public void displayInfo() {
		// return direction; // no, we're supposed to print, not return, the values!
		System.out.println("This bunny is at position "+x+", "+y);
		System.out.println("This bunny has "+carrots+" carrots");
	}
	public static void main(String[] args)
	{
		System.out.println("Testing Peter");
		NamedBunny peter = new NamedBunny(1,1,2,"Peter");
		peter.displayInfo();
		peter.hop(12);
		peter.hop(12);
		peter.hop(9);
		peter.displayInfo();
		System.out.println("Testing Emily");
		NamedBunny emily = new NamedBunny(-1,-2,99,"Emily");
		emily.displayInfo();
		emily.hop(9);
		emily.hop(9);
		emily.hop(9);
		emily.hop(12);
		emily.hop(9);
		emily.hop(12);
		emily.displayInfo();
	}

}



