Runs - Coin coin2 = new Coin(scan.nextDouble());

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// ******************************************************************** // TestBiasedCoins.java // // Creates 3 biased coins and flips each 100 times. // ******************************************************************** public class TestBiasedCoins { public static void main (String[] args) { final int FLIPS = 100; // number of coin flips //# of heads for each coin int heads1 = 0; int heads2 = 0; int heads3 = 0; // Create three coin objects System.out.println("Instantiting three coins."); System.out.println("The first coin is fair."); Coin coin1 = new Coin(); System.out.println( System.out.print("Enter the probability of heads for the second coin (0-1 inclusive): ");
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Coin coin2 = new Coin(scan.nextDouble()); System.out.print("Enter the probability of heads for the second coin (0-1 inclusive): "); Coin coin3 = new Coin(scan.nextDouble()); // Flip the coins FLIPS times, count results for (int i = 0; i < FLIPS; i++) { coin1.flip(); if (coin1.isHeads()) heads1++; coin2.flip(); if (coin2.isHeads()) heads2++; coin3.flip(); if (coin3.isHeads()) heads3++; } // Print the results System.out.println ("Coin 1 came up heads " + heads1 + " times.); System.out.println ("Coin 2 came up heads " + heads2 + " times.); System.out.println ("Coin 3 came up heads " + heads3 + " times.); } }...
View Full Document

This note was uploaded on 03/22/2010 for the course CS 202 taught by Professor Fong during the Spring '10 term at SIU Carbondale.

Ask a homework question - tutors are online