Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this exercise, you code a modified version of the Die Tracker application com

ID: 3784814 • Letter: I

Question

In this exercise, you code a modified version of the Die Tracker application completed in this lesson. Open the Dice Solution (Dice Solution.sln) file contained in the VB2015 Chap09Dice Solution-Advanced folder. The application should simulate the roll of two dice (rather than one die). It also should display the total amount rolled. For example, if one die shows two dots and the other shows four dots, the number 6 should appear in the Total box. The application should keep track of the number of times each total (from 2 through 12) is rolled. Test the application appropriately.

Explanation / Answer

public class diceGame {

    public static void main(String[] args) {

        int dice1;

        int dice2;

        int count = 0;

        int theSum = 0;

        int lowest = Integer.MAX_VALUE;

        int finalSum = 0;

        int diceSum;

        int totalSum=0;

        while (count < Integer.parseInt(args[0])) {

            count = count + 1;

            diceSum=0;

            theSum=0;

            while (diceSum!=7) {

                diceSum = 0;

                dice1 = 1 + (int) ((Math.random() * (6 - 1)) + 1);

                dice2 = 1 + (int) ((Math.random() * (6 - 1)) + 1);

                diceSum = dice1 + dice2;

                if (diceSum != 7) {

                    theSum = theSum + diceSum;

                }

                //System.out.println("the sum is "+theSum);

            }

            if (theSum > finalSum) {

                finalSum = theSum;

            }

            if (theSum < lowest) {

                lowest = theSum;

            }

            totalSum=totalSum+theSum;

        }

        double average=(double)totalSum/(Double.parseDouble(args[0]));

        System.out.println("After " + args[0] + " simulations: ");

        System.out.println("Biggest sum: " + finalSum);

        System.out.println("Smallest sum: " + lowest);

        System.out.println("The average is: "+average);

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote