Skip to content

sorry i took so long #54

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
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
<groupId>com.zipcodewilmington</groupId>
<artifactId>Dicey-Lab</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>


</project>
27 changes: 27 additions & 0 deletions 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] ++;
}
}
30 changes: 29 additions & 1 deletion src/main/java/Dice.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
public class Dice {

private int numberOfDie;

}
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;
}


}
47 changes: 46 additions & 1 deletion 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();
}
}
31 changes: 31 additions & 0 deletions src/test/java/BinsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import org.junit.Test;

public class BinsTest {
@Test
public void numberOfEachNumberTest(){
// given

// when

//then

}
@Test
public void binIncrementTest(){
// given

// when

// then

}
@Test
public void percentageOfRollTest(){
// given

// when

// then

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

import java.util.ArrayList;
import java.util.List;

public class DiceTest {
@Test
public void tossAndSumTest(){
// given
Dice dice = new Dice(2);

// when
dice.tossAndSum();

// then

}

}