This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See

and

this is what the question looks like

4. [20 marks] Craps is a dice game where two dice are rolled. Each die has six faces representing values 1, 2, 3, 4, 5, or 6.

I. If the sum is 2, 3, or 12 (called craps), you lose;
II. If the sum is 7 or 11 (called natural), you win;
III. If the sum is any other value (4, 5, 6, 8, 9, or 10), a value point is established, and you continue to roll until you either roll a sum of the value point or a 7. If the sum of the new roll is equal to the value point, then you win; if the sum of the new roll is equal to 7, then you lose.
Remember, in option (III), you continue to roll until you get a 7 or the value point.
Sample runs:
• You rolled 5 + 6 = 11; you win
• You rolled 1 + 2 = 3; you lose
• You rolled 2 + 2 = 4; you establish the value point 4;
– Roll again 2 + 3 = 5; roll
– Roll again 2 + 1 = 3; roll
– Roll again 2 + 2 = 4; you win
• You rolled 2 + 6 = 8; you establish the value point 8;
– Roll again 4 + 4 = 8; you win
• You rolled 3 + 2 = 5; you establish the value point 5;
– Roll again 1 + 1 = 2; roll
– Roll again 2 + 2 = 4; roll
– Roll again 1 + 1 = 2; roll
– Roll again 3 + 4 = 7; you lose
Develop a program that plays craps with a player three times. At the end, the program prints the number of times the player won and the number of times the player lost.

There is a picture attached
rsg.png

Master Rancher
Posts: 3296
37
What exact issues are you having?

Ryan Gordon
Ranch Hand
Posts: 86
I am having trouble making the program tell me whether the user won or lost and how many times.

Ryan Gordon
Ranch Hand
Posts: 86
I would like to make a method that will ask the user to play, then play a game, count the game and output the results. I get the concepts of counters but cant seem to get it going the way I need to...

Saloon Keeper
Posts: 3723
47
You don't need to say "extends Object", that is implied.

You have several member variables (aka "fields") such as "die1" that are hidden in your methods by local variables of the same name.

You increment gamesPlayed if the user enters "n".i

you should only create one Scanner for System.in and reuse it. This is done by declaring a static member variable just inside you class.

You are using the old style Math.random(). Use the Random class instead, it is less error prone and usually more efficient.

Ryan Gordon
Ranch Hand
Posts: 86
I was doing one of the tutorials on the coderanch website that's where I got the extends object from I forgot to remove it, thank you I will work on this an see what I come up with

Ryan Gordon
Ranch Hand
Posts: 86
Hello, I have a working program, but it does not meet the specifications. I added games played, loss count and win count. I need to make this program without those variables. I need to make use of boolean start and string status but not sure how to go about that, any suggestions?

Marshal
Posts: 57453
175
Not happy, I am afraid.
All your fields should have private access.
Why are you using a String for status? Are you using it at all in your latest version? Why was it a field rather than a local variable in the earlier versions? Does status mean win/lose? If so, ask your teacher why it has to be a String rather than an enum.
Your code isn't correctly indented; it is difficult to see where blocks start and finish. I know you often see code after a } but I think it is better always to push the enter key after a }. If you set up automatic indentation on your text editor that will help no end.
Don't create new Random objects. Use one Random object per application unless you have performance problems.
Comments like that in line 24 are useless.
Why have you got those local variables in lines 25‑26? Where are you using the two fields, if at all?
Why have you got while(true) in line 42? Can't you find a boolean expression to control that loop? Two break;s and a continue; in the same loop!
The method you are in there is much too long.

Ryan Gordon
Ranch Hand
Posts: 86
I forgot about those fields, I corrected them.  It is supposed to be used somehow to test win/loss. I can ask why it has to be a String but I will still have to use String. I will fix my indentation. I guess instead of x and y I could have used d1 and d2. I didn't think of a better way to write line 42, I am struggling and really need to improve on my skill. I had a feeling that method was too long...
I'm just having trouble because its hard to write this program because I cant think of how to use boolean start and String status...

 The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart: The WEB SERVICES and JAX-RS Course https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS