Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program that simulates a dice game. It will consist of two classes: Dice and DiceGame. ***PLEASE ADD LINE COMMENTS TO UNDERSTAND THE

Write a Java program that simulates a dice game. It will consist of two classes: Dice and DiceGame.

***PLEASE ADD LINE COMMENTS TO UNDERSTAND THE CODE***

Dice Class:

Dice (UML)

sides : int

value : int

+ Die(numSides : int)

+ roll() : int

+ getSides() : int

+ setSides(sides: int) : void

+ getValue() : int

+ setValue(value: int) : void

The Dice class will have two attributes and six methods and will permit the user to determine the number of sides the individual Die has. The roll() method will return the value of a roll for an individual Die.

DiceGame Class (Driver):

The DiceGame class will use the Dice class to play a simple dice game between the computer and the user. The program should create two instances of the Dice class (the User will be able to choose the number of sides for both Dice). One Die object is the computers die, and the other Die object is the users die. The program should have a loop that iterates 10 times. Each time the loop iterates, it should roll both dice. The die with the highest value wins (In case of a tie, roll both dice again). As the loop iterates, the program should keep count of the number of times the computer wins, and the number of times that the user wins. Also, store the results of all of the rolls for both Dice. After the loop performs all of its iterations, the program should display what numbers were rolled for both Dice, who was the grand winner, the computer or the user, and the number of games won.

Here is sample output from a run of the program (assuming both Dice have six sides):

computer: 4 2 1 6 3 5 6 2 1 6 User: 2 5 4 3 6 4 1 1 6 4

The computer was the grand winner with 6 wins!

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions

Question

What are the common methods of cost estimation?

Answered: 1 week ago

Question

Discuss how an AC is designed and implemented.

Answered: 1 week ago