/**
   Create a coin array of fixed size and initialize Coin objects and
   store it in the array. Also count how many of them are "heads" and
   how many of them are "tails".  When compiling, make sure the 
   Coin.java and this file, ObjectArrayDemo.java is in the same directory. 

   To compile: 
   $> javac ObjectArrayDemo.java
   This will produce Coin.class and ObjectArrayDemo.class bytecode files. 
   
   To run: 
   $> java ObjectArrayDemo
   OR alternatively, you may want to run the Coin classes unit test:
   $> java Coin
   
   @author A. Ozgelen
*/ 

public class ObjectArrayDemo {
    public static void main(String[] args) {
	final int NUMCOINS = 10 ;
	
	// create a Coin array
	Coin[] pocket = new Coin[NUMCOINS]; 
	int headcount = 0, tailcount = 0; 
	
	// initialize the values in the Coin array
	for(int i = 0 ; i < pocket.length ; i++) {
	    pocket[i] = new Coin();

	    // update counts for heads and tails using conditional operator
	    (pocket[i].getFace() == Coin.HEADS) ? headcount++ : tailcount; 
	    
	    /* above statement is same as: 
	    if(pocket[i].getFace() == Coin.HEADS) 
		headcount++; 
	    else 
		tailcount++;
	    */
	}

	// print result
	System.out.println("Out of " + NUMCOINS + " coins, " + 
			   headcount + " of them are heads and " +
			   tailcount +" of them are tails. Here is the list:"); 
	for(int i = 0 ; i < pocket.length ; i++) {
	    System.out.println("pocket[" + i + "]= " + pocket[i].toString());  
	}
    }
}
