# I need some analysis on a project.

• February 17th, 2013, 08:40 PM
Rain_Maker
I need some analysis on a project.
Here is my homework assignment.

To play craps, a player rolls two dice repeatedly until he wins or loses.
If he makes a 7 or an 11 on the first roll, he wins immediately.
An initial roll of 2, 3, or 12 results in a loss.
If he tosses a 4, 5, 6, 8, 9, or 10 on his first roll, then that number becomes his “point”.
After a player makes a point, he continues rolling the dice and wins or loses according to the
following rules: if he makes his point before rolling a seven, he wins;
but if he rolls a seven first, he loses.
No other values, including 2, 3, 11 or 12, affect the game’s outcome once the player has established his point.
Write a program that plays craps. Your program should allow a user to play more than one game. Typical output appears below:
Enter 0 to roll the dice: 0
You rolled a 7
You win
Play again? Enter 1 for yes: 1
Enter 0 to roll the dice: 0
You rolled a 4.
Your point is 4. Continue rolling.
Enter 0 to roll the dice: 0
You rolled a 3
Enter 0 to roll the dice: 0
You rolled a 5
Enter 0 to roll the dice: 0
You rolled a 7
You lose
Play again? Enter 1 for yes: 0
Bye

Code Java:

```/** * * Author: Gregory B Shavers * CSC- 225 Online * Lab 5 */   import java.util.*;   public class lab5 {       public static void main ( String[] args ) {   int roll, point_Roll , die1, die2, sumdie;   roll = 0; point_Roll = 0;   Scanner scan = new Scanner(System.in);   System.out.println( " Let's play a game of dice. " ); System.out.print( " Enter \"0\" zero to roll the dice. " ); roll = scan.nextInt();   die1 = (int)(6*Math.random())+1; die2 = (int)(6*Math.random())+1;   sumdie = die1 + die2;     do {   if ( sumdie == 2 || sumdie == 3 || sumdie == 12) { System.out.println( " You rolled a" + sumdie); System.out.println( " You lose!"); } else if ( sumdie == 7 || sumdie == 11) { System.out.println( " You rolled a" + sumdie ); System.out.println( " You win!"); } else if( sumdie == 1 || sumdie == 4 || sumdie == 5 || sumdie == 6 || sumdie == 8 || sumdie == 9 || sumdie == 10) { roll = sumdie; }   do {   die1 = (int)(6*Math.random())+1; die2 = (int)(6*Math.random())+1;   point_Roll = die1 + die2;   if(point_Roll == 7) { System.out.println( " You rolled a " + point_Roll ); System.out.println( " You lose! " ); } else { System.out.println( " You rolled a" + point_Roll); System.out.println( " Roll again! " ); System.out.print( " Enter \"0\" zero to roll the dice. " ); roll = scan.nextInt(); }   } while ( point_Roll != roll)                   }while ( sumdie != point_Roll);               }         }```

Okay I'm little confuse on what I should do next. Or if I'm going upon this the right way. My next step is to obvious roll the dice until it reaches 7 or its point roll. How should I go about this?

Thanks Again!
• February 17th, 2013, 10:27 PM
SunshineInABag
Re: I need some analysis on a project.
Your assignments comes with an example output, so look at what occurs first because the compiler reads top-down. The first thing is to ask the user if they want to roll by entering 0, otherwise they don't play. As you can see from the example output, if the player wins, they are asked if they want to play again, so you should think whether asking the user should be in a loop or not. In order for the dice to keep being rolled, it has to be in a loop, which you did. Your logic gets redundant with your second do-while loop because consider how the problem is structured. If the player rolls a 2,3,11 or 12, the loop ends, prints to the console and asks if they want to play again. Otherwise, for any other value other than 0, they get a point and the loop re-iterates.