{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Runs - Coin coin2 = new Coin(scan.nextDouble...

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

// ******************************************************************** // 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): ");
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

{[ snackBarMessage ]}

Ask a homework question - tutors are online