Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use Java programming Thank you EXERCISE I The Simple Game of Craps Craps is a game played with a pair of six-sided dice. In this

Use Java programming
Thank you
image text in transcribed
image text in transcribed
image text in transcribed
EXERCISE I The Simple Game of Craps Craps is a game played with a pair of six-sided dice. In this game, the shooter (the player with the dice) rolls a pair of dice and the numbers showing on the two dice are added up If the opening rol is a 7 or 11, the shooter wins the game. If the roll is a 2 (Snake eyes), 3 or 12 the shooter loses, otherwise known as "crapping out". If the shooter rolls a 4,5,6,8,9, or 10 on the opening roll, then he or she must keep rolling the dice until he/she rolls the same number known as the points or a 7 For example, if the shooter rolls a 6 on the first roll, a 10 on the second roll and a 7 on the third roll, the shooter loses since he rolled a 7 before rolling another 6. If, however, he/she rolls a 6 on the third roll, the shooter wins the game The Program In this exercise, you will write a program to play a certain number of craps games and then print out statistics on the games played. You will use two classes to implement the games, class Dice and class CrapsGame. The main method will be contained in the CrapsGame class. 2.1 The class Dice This class establishes the structure (instance variables) of a pair of dice and specifies the operations (methods) that can be performed on a pair of dice. A partial declaration of the class Dice is as follows: public class Dice private int face; private int face2; //Methods go here Page 1 of 3 2 of 3 To implement the class Dice, code the following methods: e public Dice0 //the constructor that sets both faces to 0 . public int getSumOfDice a method that returns the sum of the two faces . public void rollpreforms one roll of the two dice- random numbers between 1 and 6 2.2 The class CrapsGame This class uses the class Dice to describe the structure of the game of craps as well as operations that can be performed in the game of craps. A partial declaration of this class is as follows: public class CrapsGame t private Dice pairOfDice; contains a pair of dice- facel and face2 private boolean win; private int numOfRolls ttal number of rolls private int numOfWins equals true if game is won, false otherwise /methods here including mainO To implement the remainder of the class declaration, complete the coding of the following methods . public CrapsGame //a constructor that creates a craps game by creating a pair of Dice, sets win to false, numOfRolls to 0. e public void reset) . public void play0 . public boolean getWin . public int getNumoll l/resets the game of craps /plays the game of craps returns the value of win /returns the value in numOfRolls Method play is the method that requires the most thought. To get started on coding method play do the following: 2. obtain the sum of the dice 4. f 2, 3, or 12, shooter loses the game 6. repeat until a 7 or sum of the roll is same as sum of first roll roll the dice if 7 or 1 shooter wins the game roll dice 2. 3. getSumOfFaces0 Page 2 of 3 2.3 The main0 method Prompt user for number of games to be played Create a CrapsGame object play a game Display win or loss reset game Print statistics number of wins and losses, etc Page 3 of 3

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

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

More Books

Students also viewed these Databases questions