Write a Complete Java program for the following specification:
One of the most popular games of chance is a dice game known as “craps,” which is played in casinos and back alleys throughout the world.
The rules of the game are straightforward:
A player rolls two dice. Each die has six faces. These faces contain 1, 2,3,4,5, and 6 spots. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the sum is 7 or 11 on the first throw, the player wins. If the sum is 2, 3, or 12 on the first throw (called “craps”), the player loses (i.e., the “house” wins). If the sum is 4, 5,6,8,9, or 10 on the first throw, then that sum becomes the player’s “points.” To win, you must continue rolling the dice until you “make your points.” The player loses by rolling a 7 before making the points.
import java.util.Random;
public class DiceGame {
public static void main(String[] args) {
Random r = new Random();
//rolling dice
int d1 = r.nextInt(6) + 1;
int d2 = r.nextInt(6) + 1;
//finding sum
int sum = d1 + d2;
int points=0;
int i=0;
while (true) {
System.out.println("Sum is : " + sum);
//checking if
sum is 11 or 7 in the first throw
if (points==0
&& (sum == 7 || sum == 11)) {
System.out.println("Player losses");
break;
}
//checking if
sum is 2 3 12 in the first throw
if(sum==2||
sum==3||sum==12){
if(i==0)
System.out.println("House wins");
break;
}
i++;
if (sum == 4 ||
sum == 5 || sum == 6 || sum == 8 || sum == 9 || sum == 10) {
points=sum;
}
d1 =
r.nextInt(6) + 1;
d2 =
r.nextInt(6) + 1;
sum = d1 +
d2;
System.out.println("Player rolled "+d1+"+"+d2+" = "+sum);
}
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
Write a Complete Java program for the following specification: One of the most popular games of...
in c programming and c++filed
Exercise 1: A Game of guessing number Set the default upper and lower limits to be 1-100, and ask you to guess a number. If you do not guess the correct number, the program will nicely" automatically adjust the upper or the lower limits to save your day until you guess it. 2 0 12. 51 - 100 3 2 51 74 22 65 74 85 2 71 74 3 . 2 73 74 75...
III. Overview & Requirements:
The following description has been adopted from Deitel &
Deitel. One of the most popular games of chance is a dice game
called "craps," which is played in casinos and back alleys
throughout the world. The rules of the game are
straightforward:
A player rolls two dice. Each die has six faces. These faces
contain 1, 2, 3, 4, 5, and 6 spots. After the dice have come to
rest, the sum of the spots on...
C# Code: Write the code that simulates the gambling game of craps. To play the game, a player rolls a pair of dice (2 die). After the dice come to rest, the sum of the faces of the 2 die is calculated. If the sum is 7 or 11 on the first throw, the player wins and the game is over. If the sum is 2, 3, or 12 on the first throw, the player loses and the game is...
C++ programming language, starting out with C++. Looping Constructs Write a program to simulate the casino game "craps". It should execute N number of games so that you can compute the probability(%) of the "player" winning and the "house" winning. Probability(%) of the "player" winning = PlayerWins / N * 100. Probability(%) of the "house" winning = HouseWins / N * 100. The rules are: Player rolls two dice. When the sum is 7 or 11 on first throw, player...
please write the following program in Java
PIG is one of a family of games called jeopardy dice games, since a player's main decision after each roll is whether to jeopardize previous gains by trying for potentially even greater gains. In PIG, all players start with ZERO points, and each turn involves rolling a die to earn points. The first player to earn 100 points or more total shouts "PIG!" and wins the game. On their turn, a player does...
Please write the program in python: 3. Design and implement a simulation of the game of volleyball. Normal volleyball is played like racquetball, in that a team can only score points when it is serving. Games are played to 15, but must be won by at least two points. 7. Craps is a dice game played at many casinos. A player rolls a pair of normal six-sided dice. If the initial roll is 2, 3, or 12, the player loses....
Write a C++ game that plays Craps. Craps is a game played with a pair of dice. The shooter (the player with the dice) rolls a pair of dice and the number of spots showing on the two upward faces are added up. If the opening roll (called the ‘come out roll’) is a 7 or 11, the shooter wins the game. If the opening roll results in a 2 (snake eyes), 3 or 12 (box cars), the shooter loses,...
using python
[6] Craps is a dice-based game played in many casinos. Like blackjack, a player plays against the house. The game starts with the player throwing a pair of standard, six-sided dice. If the player rolls a total of 7 or 11, the player wins. If the player rolls a total of 2,3, or 12, the player loses. For all other roll values, the player will repeatedly roll the pair of dice until either she rolls the initial value...
Write a c++ program that simulates a million of games in craps. I am having a trouble getting to loop a million of times. I am trying to use a const for a million. This is the code so far. #include <iostream> #include <cstdlib>// contains prototypes for functions srand and rand #include <ctime>// contains prototype for function time #include <iomanip> using namespace std; int rollDice(); // rolls dice, calculates and displays sum void printstats(); int totroll = 0, games, point,...
2. "Craps" is a game played by rolling two fair dice. To play one round of this game, the player rolls the dice and the outcome is determined by the following rules: If the total number of dots is 7 or 11 (a "natural"), then the player wins. If the total number of dots is 2, 3, or 12 C'craps"), then the player loses. If the total number of dots is 4, 5, 6,8,9, or 10, then this number is...