Here is the driver:
import javax.swing.JOptionPane; public class DiceExperiment{ public static void main(String[] args){ String casino= JOptionPane.showInputDialog("enter a toss count"); int tosses=Integer.parseInt(casino); Dice d=new Dice(); d.multiToss(tosses); d.displayScoreboard(); } }
Here is the class
public class Dice{ private int[] scoreboard=new int[13]; public Dice(){ initializeScoreboard();} public void initializeScoreboard(){ for(int j=0;j<13;j++)scoreboard[j]=0; } public int tossDie(){ return (1+ (int)(6*Math.random())); } public int throwDice(){ return(tossDie()+tossDie()); } public void multiToss(int tossCount){ int score; for(int j=0;j<tossCount;j++){ score=throwDice(); scoreboard[score]++; } } public int[] getScoreboard(){return scoreboard;} public void displayScoreboard(){ for(int j=2;j<13;j++) System.out.println("toss of "+ j + " " + scoreboard[j]); System.out.println("toss count:"); } }
So this code rolls a pair of dice a number of times (# of times read from imput pane) and then reports how many times each total resulted from the rolls. I want to alter it so I enter a number into the pane and the dice continue to be rolled until each possible value of the dice throws (2,3,4,5....12) is reached at least the entered number of times. Poor description I know but heres a sample of what I want for an output...
on the input 12
2 30
3 12
4 58
5 66
6 93
7 110
8 96
9 70
10 47
11 32
12 19
toss count: 633
Any help is appreciated!