Created
July 20, 2015 22:07
-
-
Save bowbahdoe/6ad8cfedbd3907281f53 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //provided for us | |
| import java.util.Scanner; | |
| public class SevenDriver{ | |
| public static void main(String[] args){ | |
| System.out.println("Enter number of dice to toss"); | |
| Scanner s = new Scanner(System.in); | |
| int diceCount = s.nextInt(); | |
| SevenTally t = new SevenTally(diceCount); | |
| int experiments = 1000000; | |
| int wins = 0; | |
| for(int j = 0; j < experiments; j++) | |
| if(t.experiment()) wins++; | |
| System.out.println((double)wins/experiments); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.lang.Math; | |
| import java.util.*; | |
| public class SevenTally{ | |
| int diceCount; | |
| public SevenTally(int diceCount) | |
| { | |
| diceCount = diceCount; | |
| } | |
| public boolean experiment() | |
| { | |
| ArrayList<Die> diceList = new ArrayList<Die>(); | |
| for(int i = 0;i<diceCount;i++) | |
| { | |
| diceList.add(new Die()); | |
| } | |
| int arraySize = diceList.size(); | |
| for(Die dice : diceList) | |
| { | |
| System.out.println(dice.getValue()); | |
| for(Die dice2 : diceList) | |
| { | |
| if(dice.getId()!=dice2.getId()) | |
| { | |
| System.out.println("vse"); | |
| if(dice.getValue()+dice2.getValue() == 7) | |
| { | |
| return true; | |
| } | |
| } | |
| } | |
| } | |
| return false; | |
| } | |
| private class Die{ | |
| int value; | |
| double id; | |
| public Die() | |
| { | |
| value = (int)(7*Math.random() +1); | |
| id = Math.random(); | |
| } | |
| public double getId() | |
| { | |
| return id; | |
| } | |
| public int getValue() | |
| { | |
| return value; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment