Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java, please write logic in //comments Assignment : Write algorithms and programs to play non-betting Craps. Craps is a game played with a pair of

Java, please write logic in //comments

Assignment: Write algorithms and programs to play non-betting Craps. Craps is a game played with a pair of dice. In the game, the shooter (the player with the dice) rolls a pair of dice and the number of spots showing on the two upward faces are added up. If the opening roll (called the coming-out roll) is a 7 (natural) or 11 (yo-leven), the shooter immediately wins the game. If the coming-out roll results in a 2 (snake eyes), 3 (ace deuce) or 12 (box cars), then the shooter immediately loses the game (craps out). Otherwise, the game continues and the total for the coming-out roll becomes the point. If the shooters rolls the point before rolling a 7, the shooter wins. If the shooter rolls a 7 before re-rolling the point, the shooter loses, otherwise the game continues. The shooter will continue to roll until they win or lose. Refer to https://en.wikipedia.org/wiki/Craps for the basics and typical names for the sum of the die rolls. Typical play-game pseudocode:

reset game;

roll two dice and sum;

increment number of rolls;

point = sum;

if (point is 7 or is 11)

game is won;

else if (point is (not 2), is (not 3) and is (not 12)) {

do {

roll two dice and sum;

increment number of rolls;

value = sum;

} while (value is (not point) and is (not 7));

if (value is point)

game is won;

else

game is lost;

else

game is lost;

}

Output: Output will provide the analysis of running a certain number of games of Craps presented in clear, aligned, readable and attractive manner. The (win/lose) results of each game and the number of rolls will be recorded by the Analyzer class in order to facilitate an analysis of the game of Craps. Displayed analysis will include data points for:

(1) total number of games played,

(2) total number of rolls for all games played,

(3) average length (in rolls) of the games played (total rolls/total games),

(4) longest game played (in rolls).

(5) total number of games won,

(6) expected probability of winning overall,

(7) outcome of winning overall (total wins/total games),

(8) total number of wins that occurred on the coming-out roll,

(9) total number of games that ended on the opening (coming out) roll,

(10) expected probability of winning on the opening roll,

(11) outcome of winning on the coming-out roll (coming-out wins/coming-out games),

(12) expected probability of the games ending on the coming-out roll,

(13) outcome of games ending on the coming-out roll (coming-out games/total games),

(14) total number of games continuing-on after the coming-out roll (wins & losses),

(15) expected probability of the games continuing-on after the coming-out roll,

(16) outcome of games continuing-on after the coming-out roll

((total games - coming-out games)/total games),

(17) summary tally of the number of rolls for each game to finish (1 to 21+),

* Coming-out games = total number of games that ended on the opening (coming-out) roll.

The display of the summary tally data point (17) can be printed horizontal or vertical (vertical is much easier), using all tallies, whose sum should be data point (2). Use of arrays is encouraged.

Empirical outcomes (data points 7, 11, 13, 16) are based upon actual results and will be computed and displayed as a decimal percentage to 4 decimal places. Average game length - data point (3) - will be displayed to 4 decimal places also. Expected probability values (data points 6, 10, 12, 15) should be displayed to 4 decimal places, proximate to the empirical outcomes for easy comparison. Sources for expected values should be documented - external sources for data point (6), or document your actual calculations for (data points 10, 12, 15). Data point labels (1-17) should be displayed next to appropriate results. See sample output below.

Input: Input will involve prompting the user for the number of games to be analyzed, an integer between 1 and 1,000,000, inclusive. Input validation is expected.

Requirements: Use only material covered in the first eight chapters. Style requirements as discussed in class expected. Efficiency should always be considered. Round only for output. Choose the most appropriate loop/decision structures and variable types. No switch or breaks statements allowed! No magic numbers! Use constants/enumerations where appropriate - game results, roll results, and so on. No graphics.

You must write at least three programs: one for the Die class, one for the Craps class (that uses the Die class) and one for the Analyzer (Driver/Main) class (that uses the Craps class). Review chapters three and eight for assistance with creating classes.

The Die class will provide instance variables and methods to support the rolling of a fair die of any number of sides - an integer between 2-100, inclusive. Auto-correct invalid sides parameters: < 2 becomes 2, > 100 becomes 100, default = 6. The rollDie method will access the sides parameter and will return a random number between 1 and the number of sides, inclusive. Constructor(s) are required; other methods, as needed. Refer to the text - section 6.9, pages 283-284 - for a sample/similar Die class example. Use of java.util.Random is required.

The Craps class will provide constants (i.e. for sums of die rolls), instance variables and methods to play one game. A roll/throw in the game will consist of a pair of rollDie() method calls, or could be a single rollDice() method call. Since many games will be played (via the Analyzer), in addition to Constructor(s), the Craps class must also have a resetGame() method, a playGame() method, and getter methods for the game results and the number of rolls needed to decide the game. Other methods, as needed.

The Analyzer class will prompt the user for the number games to be played, validate this input, and then conduct the requisite number of games, gathering the required statistics from each game for eventual analysis. See above (Output) for details. The main() should represent your high-level view of the required tasks - other methods, as needed. All input/output should be done from the Analyzer class. Remember, your programs are not allowed to crash - validate carefully, be mindful of array bounds, and watch for division by zero

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Show Work Please

Answered: 1 week ago