Java program to implement a dice game


Question 1) Write a Java program to implement a dice game. You will need to create two classes for this assignment:

class Die is used to represent a single die (the singular form of dice). This class should have the following attributes:

• instance variables:

• sides: an int value representing the number of sides your die has (most games use 6-sided dice, but there are plenty of variations)

• value: an int value representing the current roll of the die; would be a number between 1and sides

• a Random object

• instance methods:

• two constructors:

• the default constructor must set the value of sides to 6, initialize the Random object and roll the die to get an initial value for variable value

• another constructor which takes a single argument representing the number of sides you want your die to have, sets sides to this value, and does all the same operations the other constructor does

• one mutator method called roll, which rolls the die (generates a random number between 1 and sides, which is then assigned to value)

• one accessor method called getRoll, which returns value

• a main method for testing that the other methods work

Your second class represents the game; the name of the class would be up to you. This class would also contain a main method, which is the driver for the game. You might want to include other methods, depending on how complicated your game is. You should meet the following requirements:

• Your game should use at least two dice (2 Die objects, in other words)

• Your game should have at least two players: the user and the computer

• You should have a way to keep score and to inform the user of his/her score

• The computer must play to win, if that is possible (if not a pure game of chance)

• The user should be given the option to play again once a game is completed

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Java program to implement a dice game
Reference No:- TGS04591

Expected delivery within 24 Hours