Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

Why are some analyses called horizontal and others called vertical?

Answered: 1 week ago

Question

=+1 What would you do if you were the IHR manager?

Answered: 1 week ago