Skip to content

Need to complete tests. Thanks Jen #52

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 1 commit 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
11 changes: 11 additions & 0 deletions diceRollResults.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
2 : 27650: 0.03 **
3 : 55639: 0.06 *****
4 : 83133: 0.08 ********
5 : 111209: 0.11 ***********
6 : 139205: 0.14 *************
7 : 166772: 0.17 ****************
8 : 139358: 0.14 *************
9 : 110858: 0.11 ***********
10 : 83034: 0.08 ********
11 : 55398: 0.06 *****
12 : 27744: 0.03 **
39 changes: 38 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,43 @@
<groupId>com.zipcodewilmington</groupId>
<artifactId>Dicey-Lab</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
29 changes: 28 additions & 1 deletion src/main/java/Bins.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Bins {

}
Integer[] bins;
Integer min;
Integer max;

public Bins(Integer min, Integer max) {
bins = new Integer[max - min + 1];
this.min = min;
this.max = max;
Arrays.fill(bins, 0);
}

// looking for one index array [6]
public Integer getBinValue(Integer diceRoll) {

return bins[diceRoll - min];
}

public Integer[] getBins() {
return bins;
}

public Integer incrementBins(Integer diceRoll) {
return bins[diceRoll - min] ++;
}
}
49 changes: 49 additions & 0 deletions src/main/java/Dice.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@
public class Dice {


// private static final int MAX_VALUE = 6;
private int numberOfDie;
int[] allTossedDice;


public static void main(String[] args) {
Dice die = new Dice(1);

Integer toss = die.tossAndSum();

System.out.println(toss);

}

public Dice(int numberOfDice) {
numberOfDie = numberOfDice;
}

public int tossAndSum() {
int sumOfDice = 0;
for (int i = 0; i < numberOfDie; i++) {
sumOfDice += rollDie();
}

return sumOfDice;
}

public int rollDie() {

return (int) (Math.random() * 6 + 1);
}

public int getNumberOfDie() {
return numberOfDie;
}

public void setNumberOfDie(int numberOfDie) {
this.numberOfDie = numberOfDie;
}

/*
public String toString()
{
String result = Integer.toString(faceValue);
return result;
}
*/


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

Integer numberOfDice;
Integer numberOfTosses;
Dice dice;
Bins bins;

public Simulation(Integer numberOfDice, Integer numberOfTosses) {
this.numberOfDice = numberOfDice;
this.numberOfTosses = numberOfTosses;
}

public void runSimulation() {
this.dice = new Dice(2);
this.bins = new Bins(2, 12);

for (int i = 0; i < numberOfTosses; i++) {
Integer sumUp = dice.tossAndSum();
bins.incrementBins(sumUp);
}
System.out.println("");
}

public void printResults() {
for(Integer i = 2; i <= 12; i++) {
Double percentage = (double) bins.getBinValue(i) / numberOfTosses;
System.out.printf("%2d : %7d: %.2f ", i, bins.getBinValue(i), percentage);
for(int j = 1; j < percentage * 100; j++)
{
System.out.print("*");
}
System.out.println();
}
}


public double getPercentage(Integer numberOfTosses, Bins bins) {
double percentage = 0;
for( int element : bins.getBins()) {
percentage = element/ numberOfTosses;
}
return percentage;
}

public static void main(String[] args) {
Simulation simulation = new Simulation(2, 1000000);
simulation.runSimulation();
simulation.printResults();
}
}
16 changes: 16 additions & 0 deletions src/test/java/BinsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;

class BinsTest {
@Test
public void testBin1() {



}

}
17 changes: 17 additions & 0 deletions src/test/java/DiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;


public class DiceTest {

@Test
public void testGetNumberOfDice() {
int expected = 2;

Dice die = new Dice(expected);
int actual = die.getNumberOfDie();

Assertions.assertEquals(expected, actual);

}
}