/*Written by sean * * */ import java.util.ArrayList; public class Main { private static int numDice = 10; private static int numDoubles = 2; private static int trials = 10; private static double avgScore = 0; public static void main(String[] args) { for(int t = 0; t < trials; t++){ ArrayList die = new ArrayList(); for(int i = 0; i < numDice; i++){ die.add(new Dice()); } int total = 0; int totalScore = 0; System.out.println("------ Trial " + (t + 1) + " ------"); while(total < numDoubles){ totalScore += rollDice(die); total = (multiable(die))?(total + 1):0; } System.out.println(totalScore + " = Total Score for trial " + (t+1)); avgScore += totalScore; } avgScore /= trials; System.out.println(avgScore); } public static boolean multiable(ArrayList check){ String scores = ""; boolean flag = false; for(Dice a : check){ String tmp = ""; tmp += a.getNum(); for(int i = 0; i < scores.length(); i++){ if(scores.substring(i,i+1).equals(tmp)){ flag = true; } } scores += tmp + ","; } System.out.println(scores.substring(0,scores.length()-1)); return flag; } public static int rollDice(ArrayList roll){ int b = 0; for(Dice a : roll){ a.roll(); b += a.getNum(); } return b; } } /*Written by matt * * */ import java.util.Random; public class Dice { private int num; Dice(){ roll(); } public void roll(){ num =(int)(Math.random()*6)+1; } //Returns a number between 1 and 6 public int getNum(){ return num; } }