/** * This class will test our coin methods. * * @author Mr. Merlis * @version 12/14/2007 */ import java.util.ArrayList; public class CoinTester { public static void main(String[] args) { // Creates three coins Coin penny = new Coin(); // default constructor (always makes a penny) Coin c1 = new Coin("quarter"); Coin c2 = new Coin(.10); // An ArrayList is a data structure that holds objects ArrayList handful = new ArrayList(); handful.add(new Coin("half dollar")); handful.add(new Coin("quarter")); handful.add(new Coin("dime")); handful.add(new Coin("nickel")); handful.add(new Coin("penny")); // loops as many times as we have coins for(int i = 0; i < handful.size(); i++) { System.out.println("Coin " + (i+1) + ": " + handful.get(i)); // print each coin // notice the (Coin) in the line below - casts the object to a Coin System.out.println(((Coin)handful.get(i)).flip()); // flip each coin } // System.out.println("Coin 4: " + handful.get(3)); // access the 4th coin // System.out.println(handful.size()); // print the number of coins // System.out.println("Coin 1: " + penny + "\nCoin 2: " + c1 + "\nCoin 3: " + c2); }//======================================= }