Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Hello, I am required to write a program that will play craps 3 times, I need a method that will ask the user to play the game and when the games are completed display how many times the play won and lost.
The variables I have to use are boolean start, int die1, int die2, int sum, int valuePoint, and String status.
The methods that I have to use are public void play(), public void play(int die1, int die2), and public void rollDice().
I am having issues doing this, here is what I have so far.
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.
• 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.
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?
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.
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...
Is this the real life? Is this just fantasy? Is this a tiny ad?
Free, earth friendly heat - from the CodeRanch trailboss