Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java You will design and implement two classes, Dice and Player, to simulate the dice and players in a dice game. Each player rols a

Java

image text in transcribed

You will design and implement two classes, Dice and Player, to simulate the dice and players in a dice game. Each player rols a six-sided dice once and get a score that is the number of dots on the dice face. The player who has a higher score wins otherwise it is a te. The folowing code is a client program that will use the two classes to play the game. Understand the cient program will help you to identify the states and expected behaviours of Dice and Player objects. The Hath, andom 0 method will generate a random value between 0 and 1, which will be useful to generate the number of dots on dice faces. public clasa DiceGane publie atatic void ain (seringt arga) / Create a Dice object Create two Player abjacts Player player1new Player Jahn) Player player2new Player ("Peter" Playera roll the dice playerl.rol1Dice (dice) System.out.printin ("Dice face: "+dice.getFace O) player2.roliDice (dice Syaten.out.println("Dice fsce: "dice.getFace D Display the result if (playeri.getsoore >player2.get8core System.out.printin (playerl.getNane 0"wins! Systen.out-printin (player2.getNamewins!) Systea.out.printin( It s a tie!)1 t else The followings are two sample runs of the DiceGane program. $Java DiceCane Dice face: 5 Dice face: 3 John wins $Java DiceGame Dice face: 2 Dice face: 4 Peter 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

Students also viewed these Databases questions

Question

2. Carry out the customers wishes:

Answered: 1 week ago