Question

Please do this by JAVA!!!!!!!

This program can assume all inputs are integers representing whole dollar amounts.

1) Ask the user for a stake amount (initial amount of money available to bet). Check to make the sure user enters a correct number (over 0). State a descriptive error to re-prompt the user if the stake amount is not a correct amount like a negative number).

2) Ask the thrower for their bet. The amount of money the thrower has to bet (the stake amount) should be displayed before the throw to help the thrower make a bet. You must verify correct bets (ex: bet amount must be greater than or equal to than stake amount that is left). The thrower must have money to be able to bet on a throw (stake money left > 0) or the game will post a message and automatically end. At this point, if the thrower wishes to stop the game, then the thrower should enter a bet of 0.

3) Throw a pair of dice. A message should display telling the bettor to throw the dice by pressing any key. When the thrower wins, twice the bet money is returned back into the thrower’s total stake. When the thrower loses, the bet money is deducted from the thrower’s total stake. Throw results: a) If the total value of the dice is 7 or 11, the thrower is an instant winner. b) If the total value of the dice is 2, 3, or 12, the thrower is an instant loser. c) If the total is anything else, remember this total, it is called the “point”. The thrower throws again: i) If the new point throw total is equal to the “point”, the thrower wins. ii) If the new point throw total is a 7, the thrower loses. iii) If the new point throw total is anything else than a 7 or the point, the thrower must keep throwing until the thrower wins by getting a point roll or loses by getting a 7. d) When the thrower is done with each cycle of throwing, the game should display the new adjusted stake amount.

4.) When throwing cycle is done an ending condition occurring (no money left, win or lose), the program will report the final stake amount the thrower has left and how many total throws the thrower made during the game. Recall that the game ends when: • The thrower ends the game by entering a zero bet at the start of a throw cycle. • The stake ends up at a zero amount, the program automatically ends the game.

A sample of a solution program output is included at the end of this assignment. Use the sample solution output as a required guide in designing the program output. Your output must be well formatted and match the formatting in the sample output.

Lets own a casino! What is your stake amount ? -1 You have to enter a 0 or positive amount of money to bet with. Try again!Lets own a casino! The point is 6 Throw em again and hope that lucks on your side! Press any key to throw the dice Die 01 i

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Java code

import java.util.Random;
import java.util.Scanner;

public class Casino {
    private static Scanner keyboard = new Scanner(System.in);
    public static void main(String[] args)
    { int stakeAmount = validateStakeAmount("What is your stake amount ? ");
        while (true) {

            int betAmount = validateBetAmount("What will you bet ? ", stakeAmount);
            if(betAmount ==0)
                break;
            int point = 0;
            int rollCount = 0;
            do {


                System.out.println("Press any key to throw the dice");
                keyboard.nextLine();
                // String key = keyboard.nextLine();
                int diceResult = 0;
                if (keyboard.hasNextLine()) {
                    int dice1 = getRandomNumber();
                    int dice2 = getRandomNumber();
                    diceResult = dice1 + dice2;
                    System.out.println("Die 01 is " + dice1);
                    System.out.println("Die 02 is " + dice2);
                    System.out.println("The Dice throw results : " + diceResult + "!");
                    rollCount++;
                }
                /**
                 *  the thrower wins, twice the bet money is
                 *  returned back into the thrower’s total stake.
                 *  If the total value of the dice is 7 or 11,
                 *  the thrower is an instant winner
                 */
                if (diceResult == 7 || diceResult == 11) {
                    stakeAmount = stakeAmount + 2 * betAmount;
                    System.out.println("Congrats, You win..");
                    break;
                }
                /**
                 * When the thrower loses,
                 * the bet money is deducted from the thrower’s total stake.
                 * If the total value of the dice is 2, 3, or 12,
                 * the thrower is an instant loser.
                 */
                else if (diceResult == 2 || diceResult == 3 || diceResult == 12) {
                    stakeAmount = stakeAmount - betAmount;
                    System.out.println("Sorry, you lose.");
                    break;
                }
                /**
                 * If the total is anything else, remember this total,
                 * it is called the “point”
                 */
                else {
                    if (diceResult == point) {
                        stakeAmount = stakeAmount + 2 * betAmount;
                        System.out.println("Congrats, You win..");
                        break;
                    }

                    if (point == 7) {
                        //loses
                        stakeAmount = stakeAmount - betAmount;
                        System.out.println("Sorry, you lose.");
                        break;
                    }
                    point = diceResult;
                    System.out.println("The point is " + point);
                    System.out.println("throw em again and hope that luck's on your side!");
                }
            } while (true);
            if (stakeAmount == 0) {
                System.out.println("Out of money, Game ends. ");
                System.out.println("Roll Count: " + rollCount);
                System.out.println("Final stake amount: " + stakeAmount);
                break;
            }
            System.out.println("Roll Count: " + rollCount);
            System.out.println("Final stake amount: " + stakeAmount);
        }
    }

    /* ====================================================== */
    private static int getRandomNumber()
    {
        Random random = new Random();
        int number  = random.nextInt(6)+1;
        return number;
    }
    private static int validateStakeAmount(String prompt)
    {
        System.out.print(prompt);
        int amount  = keyboard.nextInt();
        while (amount<=0)
        {
            System.err.println("You have to enter a 0 or positive amount of money to bet with...Try again!");
            System.out.print(prompt);
             amount  = keyboard.nextInt();
        }
        return amount;
    }
    private static int validateBetAmount(String prompt, int stakeAmount)
    {
        System.out.print(prompt);
        int amount  = keyboard.nextInt();
        while (amount<0 ||amount>stakeAmount )
        {
            if(amount>stakeAmount)
            {
             System.err.println("Sorry, can't bet more than your stake !");
            }
            else {
                System.err.println("You have to bet a positive number less than or equal to the stake amount!");
            }

            System.out.println("Current stake amount: "+stakeAmount);
            System.out.print(prompt);
            amount  = keyboard.nextInt();
        }
        return amount;
    }
}

//Output

Die 01 is 2 Die 02 is 4 The Dice throw results : 6! The point is 6 throw em again and hope that lucks on your side! Press an

//if you need any help regarding this solution ............ please leave a comment ........... thanks

Add a comment
Know the answer?
Add Answer to:
Please do this by JAVA!!!!!!! This program can assume all inputs are integers representing whole dollar...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

    Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

  • C# Code: Write the code that simulates the gambling game of craps. To play the game,...

    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...

  • Craps

    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,...

  • For this lab you will write a Java program that plays the dice game High-Low. In...

    For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------ ------ High 1 x Wager Low 1 x Wager Sevens 4 x...

  • please write the following program in Java PIG is one of a family of games called...

    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...

  • You will write a two-class Java program that implements the Game of 21. This is a...

    You will write a two-class Java program that implements the Game of 21. This is a fairly simple game where a player plays against a “dealer”. The player will receive two and optionally three numbers. Each number is randomly generated in the range 1 to 11 inclusive (in notation: [1,11]). The player’s score is the sum of these numbers. The dealer will receive two random numbers, also in [1,11]. The player wins if its score is greater than the dealer’s...

  • Hello, Could you please help me code this program in Java? It is important that all...

    Hello, Could you please help me code this program in Java? It is important that all rules are carefully followed. Using the PairOfDice class from PP 4.9, design and implement a class to play a game called Pig. In this game, the user competes against the computer. On each turn, the current player rolls a pair of dice and accumulates points. The goal is to reach 100 points before your opponent does. If, on any turn, the player rolls a...

  • Java Program Note: no break statements or switch staements High, Low, Sevens For this lab you...

    Java Program Note: no break statements or switch staements High, Low, Sevens For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------...

  • Using Java You are helping a corporation create a new system for keeping track of casinos...

    Using Java You are helping a corporation create a new system for keeping track of casinos and customers. The system will be able to record and modify customer and casino information. It will also be able to simulate games in the casino. Customer-specific requirements You can create new customers All new customers have a new customerID assigned to them, starting with 1 for the first, 2 for the second, 3 for the third, ect. New customers have names and monetary...

  • Create a Java text-based simulation that plays baccarat between two players. In baccarat, there i...

    Create a Java text-based simulation that plays baccarat between two players. In baccarat, there is a banker and there is a player. Two cards are dealt to the banker and two cards to the player. Both cards in each hand are added together, and the objective (player) is to draw a two or three-card hand that totals closer to 9 than the banker. In baccarat, the card values are as follows: • 2–9 are worth face value • 10, J,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT