Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Craps game: Following question: This program should play two dice (1-6) it should roll the dices until the total sum of the two dices is

Craps game:

Following question:

This program should play two dice (1-6) it should roll the dices until the total sum of the two dices is 4, 5, 6, 8, 9, or 10. This number turns to players point.

after point has been stored, program should continue rolling dices until the total value of the dice is the same number of stored value in that case you WIN or if you throw a 7 in that case you lose.

(NO ARRAY LIST ALLOWED)

Problem: My program doesn't keep on going after a valid point has been stored.

I have the following so far:

class xyz

{ public static void main(String[] args) { boolean x = true; while (x) { int score = doRoll(); if ( score == 4 || score == 5 || score == 6 || score == 8 || score == 9 || score == 10) { x = false; break; } }

while (x) { int score = doRoll(); if (score == points ) { x = false; System.out.println("You Win!"); break;

} else if (score == 7) { x = false; System.out.println("you lose!"); } }

}

static int doRoll() { int points = 0; int dice1; int dice2; while (!isValidNumber(points)) { dice1 = rint(1, 6); dice2 = rint(1, 6); points = dice1 + dice2; System.out.println("Computer rolls a " + dice1 + " and a " + dice2 + ", for a total of " + points); } System.out.println(points + " is now your established POINT"); return points; }

static int rint(int a, int b) { return a + (int) ((b - a + 1) * Math.random()); }

static boolean isValidNumber(int number) { return (number == 4 || number == 5 || number == 6 || number == 8 || number == 9 || number == 10); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions