The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

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

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.