/**
 * @author CPSC Instructors
 * @date 7 Apr 2010
 *
 * Finish BunnyHerd class we started last time. Design alternatives discussed.
 */
public class BunnyHerd {

	private int maxBunnies;
	private String herdName;

	private int herdCount;
	private NamedBunny[] bunnies;

	public BunnyHerd(int maxBunnies, String herdName) {
		this.maxBunnies = maxBunnies;
		this.herdName = herdName;
		bunnies = new NamedBunny[maxBunnies];
		herdCount = 0;
	}
	public void addBunny(int xPos, int yPos, int carrots, String name) {
		// error checking!
		if (herdCount < maxBunnies) {
			bunnies[herdCount] = new NamedBunny(xPos,yPos,carrots,name);
			herdCount++;
		}
	}
	public void deleteBunny(String name) {
		//		for (int i=0; i < herdCount && !bunnyKilled; i++) { 
	        // need to keep checking all bunnies with multiple names, so not correct

		for (int i=0; i < herdCount; i++) { // keep checking, even after killed a bunny
			//if (bunnies[i].getName().equals(name) == true) { 
		        // legal, but verbose
			if (bunnies[i].getName().equals(name)) { // more concise!
				bunnies[i] = null; // bunny RIP
				// inefficient but correct to keep
				// checking whole array, keep track if
				// we're done
				//bunnyKilled = true;
				// but wait! could have multiple
				// bunnies with same name. must keep
				// checking.
			}
		}
	}
	
	public void printHerd() {
	        // loop through all *active* bunnies
		for (int i=0; i < herdCount; i++) { 
			if (bunnies[i] != null) { 
				System.out.println(bunnies[i].toString());
			}
			// relying on the internals of the NamedBunny
			// class to do the work of finding the
			// information, instead of grabbing all the
			// ourselves with getter methods
		}
	}
}
	

