Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a JAVA program that demonstrates the Dice class from the previous problem. This program will roll two Dice objects repeatedly, add the value from

Write a JAVA program that demonstrates the Dice class from the previous problem. image text in transcribed

This program will roll two Dice objects repeatedly, add the value from the two dices together, to display a total for that roll.

-Use a loop to do this 150 times. This simulates 150 independent rolls of two dice.

-The program should keep track of how many times each total value (from 2 - 12) appears, and output the totals at the end.

Program output should look like this:

image text in transcribed

image text in transcribed

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

These were the Dice class requirements from "previous problem" as mentioned above, so you have an idea:

Write a class named Dice. The Dice class should have the following field:

A private integer named faceShowing. The faceShowing field will hold an integer between 1-6 indicating the side of the dice that is facing up.

The Dice class should have the following methods:

-A no-arg constructor that randomly determines which side is up and sets faceShowing accordingly.

-A void method named roll() that simulates rolling the dice. When the roll method is called, it randomly determines the number that is shown on the dice, and sets faceShowing accordingly.

-A method named faceShowing() that returns the value of the faceShowing field.

Write a program that demonstrates the Dice class. The program should create an instance of the class and display the side that is initially facing up.

Dice roll: 1+3=4 Dice roll: 2+2=4 Dice roll: 5+6=11 \begin{tabular}{l} Dice roll results \\ \hline 2 was rolled 4 times. \\ 3 was rolled 2 times. \\ 4 was rolled 5 times. \\ 5 was rolled 8 times. \\ 6 was rolled 5 times. \\ 7 was rolled 8 times. \\ 8 was rolled 7 times. \\ 9 was rolled 2 times. \\ 10 was rolled 5 times. \\ 11 was rolled 2 times. \\ 12 was rolled 2 times. \end{tabular}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions