CSC 172 - Intro to Algorithms and Data Structures

Dr. R. M. Siegfried

Assignment #1 - Playing A Game Of Craps

Due Monday, February 3, 2014

In the game of craps, a pass line bet proceeds as follows: Two six-sided dice are rolled; the first roll in a craps round is called "the come out roll." A come out roll of 7 or 11 automatically wins, and a come out roll of 2, 3, or 12 automatically loses. If 4, 5, 6, 8, 9, or 10 is rolled, that number becomes the point. The player keeps rolling the dice until either 7 or point is rolled. If the point is rolled first, then the player wins the bet. If a 7 is rolled first, then the player loses.

Write a program that simulates a game of craps without human intervention. Instead of asking for a wager, the program should announce whether the player won or lost. Make sure that the program is well-organized, documented and properly divided into separated methods.

NB: to generate a random number x, where 0 ≤ x < n, use

Random generator = new Random();
int roll = generator.nextInt(6) + 1;
Use it twice to get the roll of two dice.

[Back to the Assignment Index]