import java.util.*;

class Cow {
	public void makeSound() {
		System.out.println("Mooo Mooo");
	}
}

class Farm {
	//An array of Cow references
	private Cow[] cowsOnFarm;

	//Number of Cow on farm so far
	private int _numAnimals;

	public Farm(int size) {
		cowsOnFarm = new Cow[size];

		//Initialize all references to null 
		for (int i = 0; i < size; i++) {
			cowsOnFarm[i] = null;
		}

		_numAnimals = 0;
	}


	public boolean add(Cow newCow) {
		//Can we take in another cow?
		if (_numAnimals == cowsOnFarm.length)
			return false;

		//Add cow to farm
		cowsOnFarm[ _numAnimals ] = newCow;
		_numAnimals++;

		return true;
	}

	public void singChorus() {

		for (int i = 0; i < _numAnimals; i++) {
			cowsOnFarm[i].makeSound();
		}
	}

}

class OldMcDonaldCow {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int userChoice;
		Farm myFarm;

		myFarm = new Farm(10);        //10 is just an example

		do {
			System.out.print("Choose 1. Add more cow, 2. Farm chorus, 3. exit ->");
			userChoice = sc.nextInt();

			switch (userChoice) {
				case 1:
					if ( myFarm.add( new Cow() ) ) {
						System.out.println("Cow added!");
					} else {
						System.out.println("Farm full!");
					} 
					break;
				case 2:
					System.out.println("All farm animals start to sing:");
					myFarm.singChorus();
					break;
				case 3:
					System.out.println("Bye bye!");
					break;
			}
		} while (userChoice != 3);   

	}

}

