Question: JAVA ITCS 1213 Lab 5 Purpose: To use a class in multiple applications, Part 1: Write a class that simulates a Die (singular of Dice)

JAVA

ITCS 1213 Lab 5

Purpose: To use a class in multiple applications,

Part 1: Write a class that simulates a Die (singular of Dice) that is used in may games.

The class needs two fields, the number of sides and the value of the side up (the face). The value of the face ranges from 1 to the number of sides. This means a Die with six ides can have a face value of 1 to 6. A Die with 10 sides can have a face value of 1 to 10.

Write two constructor methods. The default constructor will set the number of sides to 6. Use the Random class to set the value of the face.

Write two set( ) methods and two get( ) methods.

Write a roll( ) method that changes the value of the face.

Write a toString( ) method that returns the value of the face in a textual representation: --------- | 5 | ---------

Test the Die class using the BlueJ debugging toos.

Part 2: One of the most popular games of chance is a game played with two dice. The game is called craps. As you know, a standard die is a small cube with each of the six sides displaying a number between 1 and 6. Normally, a number is represented as a set of spots, so each side will have 1, 2, 3, 4, 5, or 6 spots on it. Of course, no two sides of a die (honest ones, anyway) have the same number of spots.

Here are the rules for playing craps:

A player rolls 2 dice. After the dice come to rest, the sum of the spots on the 2 upward faces is calculated.

If the sum is 7 or 11 on the first throw, the thrower wins and the game is over.

If the sum is 2, 3, or 12 on the first throw, the thrower loses and the game is over.

If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then that sum is known as the throwers point. If the third case occurs, in order to win, the player must keep throwing the dice until he/she makes his point, that is, the sum is equal to his point. The thrower loses if he throws a 7 before making his point. In either case (making point or throwing a 7), the game is over. Write a program that simulates a craps game. Your program should do the following: Play a game of craps. This requires the use of the Die class you can download from our Canvas page.

When a game is finished, the program will ask the user if he/she wants to play another game. The program should either play another game or terminate, based on the user response.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!