package edu.bloomu.ch7a;

/**
 * Calculates the probability of each possible sum when rolling a pair of dice. 
 * 
 * @author Drue Coles
 */
public class DiceSums3 {

    public static void main(String[] args) {

        final int sides = 6;
    
        // Iterate over all possible pairs of dice rolls and count sums.
        int[] sums = new int[2 * sides + 1];
        for (int i = 1; i <= sides; i++) {
            for (int j = 1; j <= sides; j++) {
                sums[i + j]++;
            }
        }

        // Format and display results.
        System.out.println("SUM PROBABILITY");
        final int numPairs = sides * sides; 
        for (int i = 2; i <= 2 * sides; i++) {
            
            double prob = (double) sums[i] / numPairs * 100;
            
            // sequence of stars for a bar chart
            String star = "\u2605";
            int numStars = (int) Math.round(prob);
            
            System.out.printf("%3d %4.1f%% %s %n", i, prob, stars.repeat(numStars));
        }
    }
}