/**
 * @author CPSC Instructors
 * @date 7 Apr 2010
 *
 * Minor fix to NamedBunny class from last lecture: name field should be private!
 */

public class NamedBunny {
	private int x,y,carrots;
	private 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 in first codewriting pass 
		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");
//		System.out.println("This bunny is named "+name);
		
		System.out.println(toString()); // safer than having duplicate code, as above
	}
	
	public String toString() {
		return("This bunny is at position "+x+", "+y + " with "+carrots+" carrots" + " and named "+name);
	}


}



