Project 3 – The Game of Craps

DUE: October 22nd, 2004

 

 

Introduction

 

Craps is played with two dice which are rolled together. The sum of these two dice is computed and if the sum is:

 

·         2, 3, or 12 – the player loses. 

·         7 or 11 – the player wins.

·         Any other number is referred to as the “point.” The goal then becomes to keep rolling the dice until:

o       The player rolls a 7 – the player loses

o       The player rolls the “point” – the player wins.

 

 

Examples

 

 

Ex 1:

 

Roll 1: Player rolls a 12. Player loses.

 

Ex 2:

 

Roll 1: Player rolls a 7. Player wins.

 

Ex 3:

 

Roll 1: Player rolls a 5. The “point” becomes 5.

Roll 2: Player rolls a 9.

Roll 3: Player rolls a 7. Player loses.

 

Ex 4:

 

Roll 1: Player rolls a 10. The “point” becomes 10.

Roll 2: Player rolls a 2.

Roll 3: Player rolls a 10. Player wins.

 

 


Assignment

 

Your job on this assignment is to make a simple craps game.  In this game the player will enter his or her name, the program will display a welcome message, and ask if the player would like to play or quit.  The program will then roll two dice, and display them and their total.  If the player has won, display a message congratulating them. If the player has lost, report it to them. Otherwise, store this first roll as the “point” roll and keep rolling until the player wins or loses.  When the game ends, ask if the player would like to play again.

 

Ex:

 

Welcome to Jon’s Casino!

Please enter your name: Jonathan

Would you like to “play” or “quit”? play

 

You have rolled 5 + 2 = 7

You Win!

 

Would you like to play again (Y/N)? N

 

Goodbye, Jonathan!

 

 
 

 

 

 

 

 

 

 

 

 

 

 

 

 


Note that you need not match this exactly; it is only shown to give you an idea of how to proceed.

 

Advice

 

Even though we haven’t covered all of the material you will need from Chapter 3 yet, you can still get started with creating the class and doing some simple input. I suggest you start soon, and work on it as we go over the topics to reinforce what we learn in class.

 

Please use proper indentation and variable naming style.  Add descriptive comments to explain portions of your code. A portion of the grade will be determined by style.

 

Since we haven’t studied random numbers yet, here’s the code to roll a single die.  It returns a number 1 to 6 inclusive:


class Craps {

            public static void main(String[] args) {

                        //Your code here

                        int roll1 = rollDie();

            }

 

public static int rollDie() {

                        return (int)(Math.random() * 6)+1;

}

}

 
 

 

 

 

 

 

 

 

 

 

 

 

 


If you’re having problems try to work them out on your own for a while before emailing me or the TA.  If you don’t figure it out, include in the email what’s happening, your code if relevant, and what steps you’ve already tried.

 

Project Submission

 

Submission will be the same as for the previous project, copying your java file into the submit directory.

 

Good luck and try to have fun while doing this!