Using java, need to create a craps game program that can keep track on a user's wins / losses and also prompt user to place bets.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Using java, need to create a craps game program that can keep track on a user's wins / losses and also prompt user to place bets.

Expert Solution
Step 1

Craps is a dice game in which the players make wagers on the outcome of the roll or a series of rolls of a pair of dice.

Each round has 2 phases: Come Out and Point.

A Come Out roll of 2, 3, or 12  are called Craps as the shooter is said to 'crap out' ending the round with players losing their Pass Line bets.

A Come Out roll of 7 or 11 is called a Natural resulting in a win for Pass Line bets.

The shooter continues to make Come Out rolls until he rolls 4, 5, 6, 8, 9, or 10, which number becomes the Point.

The dealer then moves an On button to the point number that indicates the second phase of the round.

If the shooter rolls the point number, the result is a win for bets on the Pass Line.

If the shooter rolls a seven (a Seven-out), the pass line loses and the round ends.

 

Step 2

The complete Java code for the Craps game is given below:

import java.util.*;
import java.util.Random;
public class Main
{
public static void main(String[] args) throws java.lang.Exception {
  int wins = 0;
  int loss = 0;
  Scanner sc1= new Scanner(System.in); 
   System.out.print("Enter the number of Rolls: ");  
    int n= sc1.nextInt();
  for (int i = 0; i <n; i++) {
    System.out.println("Roll the dices");
    Scanner sc= new Scanner(System.in);    
    System.out.print("Enter Your Bet: ");  
    int a= sc.nextInt();  
    int score = roll();
    System.out.println("\n score " + score);

    if (score == 7 || score == 11) {
      System.out.println("\n Score = " + score);
      System.out.println("User wins");
      wins = wins + 1;
    } else if (score == 2 || score == 3 || score == 12) {
      System.out.println("\n Score = " + score);
      System.out.println("User loses");
      loss = loss + 1;
    } else {
      int point = score;
      System.out.println("\n Point = " + point);
      while (true) {
        score = roll();
        System.out.println("\n Score new = " + score);
        if (score == point) {
          System.out.println("\n User wins");
          wins = wins + 1;
          break;
        }
        if (score == 7) {
          System.out.println("\n User loses");
          loss = loss + 1;
          break;
        }
      }
    }
  }

  System.out.println("\n Number of wins by the user = " + wins
      + " and Number of losses by the user = " + loss);
}
public static int roll() {
  Random randomGenerator = new Random();
  int dice1 = randomGenerator.nextInt(6) + 1;
  int dice2 = randomGenerator.nextInt(6) + 1;
  System.out.println("\n dice1 = " + dice1 + " dice2 = " + dice2);
  return dice1 + dice2;
}
  
}

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education