Skip to content

Completed Lab. Created XiongResults.md for results. #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions XiongResults.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#Xiong's Results

```java
***
Simulation of 2 dice tossed for 1000000 times.
***

2 : 27758: 0.03 **
3 : 55522: 0.06 *****
4 : 83600: 0.08 ********
5 : 110834: 0.11 ***********
6 : 138949: 0.14 *************
7 : 166409: 0.17 ****************
8 : 138581: 0.14 *************
9 : 111219: 0.11 ***********
10 : 83506: 0.08 ********
11 : 55580: 0.06 *****
12 : 28042: 0.03 **
```
49 changes: 49 additions & 0 deletions src/main/java/Bins.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@

public class Bins {
int two = 0;
int three = 0;
int four = 0;
int five = 0;
int six = 0;
int seven = 0;
int eight = 0;
int nine = 0;
int ten = 0;
int eleven = 0;
int twelve = 0;

public void storeBin(int result) {
switch (result) {
case 2:
two++;
break;
case 3:
three++;
break;
case 4:
four++;
break;
case 5:
five++;
break;
case 6:
six++;
break;
case 7:
seven++;
break;
case 8:
eight++;
break;
case 9:
nine++;
break;
case 10:
ten++;
break;
case 11:
eleven++;
break;
default:
twelve++;
break;
}
}

}
23 changes: 23 additions & 0 deletions src/main/java/Dice.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
public class Dice {
public int faceValue;

public Dice() {
this.faceValue = (int)((Math.random() * 6) + 1);
}

public static Integer diceToss2() {
Dice dice1 = new Dice();
Dice dice2 = new Dice();

return dice1.faceValue + dice2.faceValue;
}

// public static Integer diceToss5() {
// Dice dice1 = new Dice();
// Dice dice2 = new Dice();
// Dice dice3 = new Dice();
// Dice dice4 = new Dice();
// Dice dice5 = new Dice();
//
// return dice1.faceValue + dice2.faceValue + dice3.faceValue + dice4.faceValue + dice5.faceValue;
// }



}
30 changes: 30 additions & 0 deletions src/main/java/Simulation.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
public class Simulation {

public static void main(String[] args) {
Simulation simulate = new Simulation();

simulate.simulate2Dice(1000000);


}

public void simulate2Dice(int timesToSimulate) {
int counter = 0;
Bins results = new Bins();
while (counter < timesToSimulate) {
results.storeBin(Dice.diceToss2());
counter++;
}
System.out.println("***");
System.out.println(String.format("Simulation of 2 dice tossed for %d times.", timesToSimulate));
System.out.println("***\n");
System.out.println(String.format(" 2 : %8d: %5.2f **", results.two, (double)results.two/timesToSimulate));
System.out.println(String.format(" 3 : %8d: %5.2f *****", results.three, (double)results.three/timesToSimulate));
System.out.println(String.format(" 4 : %8d: %5.2f ********", results.four, (double)results.four/timesToSimulate));
System.out.println(String.format(" 5 : %8d: %5.2f ***********", results.five, (double)results.five/timesToSimulate));
System.out.println(String.format(" 6 : %8d: %5.2f *************", results.six, (double)results.six/timesToSimulate));
System.out.println(String.format(" 7 : %8d: %5.2f ****************", results.seven, (double)results.seven/timesToSimulate));
System.out.println(String.format(" 8 : %8d: %5.2f *************", results.eight, (double)results.eight/timesToSimulate));
System.out.println(String.format(" 9 : %8d: %5.2f ***********", results.nine, (double)results.nine/timesToSimulate));
System.out.println(String.format("10 : %8d: %5.2f ********", results.ten, (double)results.ten/timesToSimulate));
System.out.println(String.format("11 : %8d: %5.2f *****", results.eleven, (double)results.eleven/timesToSimulate));
System.out.println(String.format("12 : %8d: %5.2f **", results.twelve, (double)results.twelve/timesToSimulate));

}

}