/*
Author: Aaron Hurt
Class: COMP 313, Intro to Java
Time: Saturday, 8 to 1
Assignment: Homework 5
Program description: Show percentages of the combinations from
rolling two 6 sided die given a certain number of rolls
*/


import java.util.*;
import java.text.*;

public class Homework5 {
	public static void main(String[] args) {
		//Set up variables to count number of rolls
		int dice[];
		dice= new int[11];
		for (int x=0; x<11; x++) dice[x]= 0;
		//Set up variables to calculate percentages
		double percent[];
		percent= new double[11];
		//Create the random number generator.
		Random generator = new Random();
		//The decimal format object will be used to control the average output.
		DecimalFormat df= new DecimalFormat("0.000");
		//Ask the user how many times to roll the dice.
		int numberRolls= GetData.integerRange(0,1000000,"Roll 2 dice how many times (0 to exit)?");
		//Use a for loop to control how many times the dice is rolled.
		while(numberRolls != 0) {
			for(int loop= 1; loop <=numberRolls; loop++) {
				//Use the random number generator to roll two dice of 1-6.
				switch((generator.nextInt(6) + 1) + (generator.nextInt(6) + 1)) {
					case 2: dice[0]++;break;
					case 3: dice[1]++;break;
					case 4: dice[2]++;break;
					case 5: dice[3]++;break;
					case 6: dice[4]++;break;
					case 7: dice[5]++;break;
					case 8: dice[6]++;break;
					case 9: dice[7]++;break;
					case 10: dice[8]++;break;
					case 11: dice[9]++;break;
					case 12: dice[10]++;break;
				} //end switch statement

			} //end for loop
			//Calculate percentages and output totals
			int y= 0;double percentTotal= 0;
			for (int x=0; x<11; x++) {
				y= x+2;
				percent[x]= (double)dice[x]/numberRolls*100;
				percentTotal+= percent[x];
				System.out.print(y+" was rolled: "+dice[x]+" times (");
				System.out.println(df.format(percent[x])+"%)");
			}
			System.out.println("\n\nTotal of all percentages: "+df.format(percentTotal)+"%\n\n");
			for (int x=0; x<11; x++) dice[x]= 0;
			numberRolls= GetData.integerRange(0,1000000,"Roll 2 dice how many times (0 to exit)?");
		}
	}//end main
} //end OneDice class