/* Java application illustrating the use of objects of the TossableCoin4 class. */ public class TossableCoin4App { public static void main(String[] args) { // Create a new coin object and assign it to variable 'coin'. // Notice the specified "heads probability". TossableCoin4 coin = new TossableCoin4(0.35); final int NUM_TOSSES = 15; // Toss the coin several times. for (int i=1; i <= NUM_TOSSES; i = i+1) { coin.toss(); //System.out.println(coin); //Don't print anything! } // Report how many times each of HEADS and TAILS was tossed. System.out.println("\n# times coin was tossed: " + coin.tossCount()); System.out.println("# times Heads was tossed: " + coin.headsCount()); System.out.println("# times Tails was tossed: " + coin.tailsCount()); // Report all the toss results. for (int i=1; i <= NUM_TOSSES; i = i+1) { if (coin.wasHeads(i)) { System.out.printf("Toss %d: HEADS\n", i); } else { System.out.printf("Toss %d: TAILS\n", i); } } } }