Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package lukelafrenieremath1350lab04;
- /**
- *
- * @author Shifteh
- */
- import java.util.Random;
- public class LukeLafreniereMATH1350Lab04 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- int rounds = 1000;
- float playerOneWins = 0;
- float playerTwoWins = 0;
- float playerOneWinRate = 0;
- float coinsFlipped = 0;
- float flipResult = 0;
- int playerOneHeads = 0;
- int playerTwoHeads = 0;
- for (int i = 0; i < rounds; i++) {
- playerOneHeads = 0;
- playerTwoHeads = 0;
- coinsFlipped = 0;
- while (playerOneHeads < 3 || playerTwoHeads < 3) {
- Random flipRandom = new Random();
- flipResult = flipRandom.nextInt(2) + 1;
- coinsFlipped++;
- if (flipResult == 1) {
- if (coinsFlipped % 2 == 1) {
- playerOneHeads++;
- } else if (coinsFlipped % 2 == 0) {
- playerTwoHeads++;
- }
- }
- if (playerOneHeads == 3) {
- playerOneWins++;
- } else if (playerTwoHeads == 3) {
- playerTwoWins++;
- }
- }//End of while loop
- }//End of for loop\
- System.out.println(playerOneWins);
- System.out.println(playerTwoWins);
- playerOneWinRate = (playerOneWins / rounds);
- System.out.println("after " + rounds + " rounds player 1 would win "
- + playerOneWinRate + "% of the time");
- }//End of main
- }//End of class
Add Comment
Please, Sign In to add comment