Question: import java.util.Random; public class Dice { /** The first die. */ private final int first; /** The second die. */ private final int second; /**

 import java.util.Random; public class Dice { /** The first die. */

import java.util.Random; public class Dice {

/** The first die. */ private final int first;

/** The second die. */ private final int second;

/** The third die. */ private final int third;

/** * Constructs a new Dice object with the given face values. * * @param first value of first die * @param second value of second die * @param third value of third die */ public Dice(int first, int second, int third) { this.first = first; this.second = second; this.third = third; }

/** * Constructs a new Dice object with random face values. */ public Dice() { Random random = new Random(); this.first = random.nextInt(6) + 1; this.second = random.nextInt(6) + 1; this.third = random.nextInt(6) + 1; }

/** * Adds the values of all dice together. * * @return sum total of all dice values */ public int addValues() { return this.first + this.second + this.third; }

/** * Counts how many dice have the given face value. * * @param face value to look for (1 to 6) * @return number of dice that match (0 to 5) */ public int countValues(int face) { int count; count = 0; if (this.first == face) { count = count + 1; } if (this.second == face) { count = count + 1; } if (this.third == face) { count = count + 1; } return count; }

/** * @return The number showing on the first die. */ public int getFirst() { return this.first; }

/** * @return The number showing on the second die. */ public int getSecond() { return this.second; }

/** * @return The number showing on the third die. */ public int getThird() { return this.third; }

}

This is the other file:

import java.util.Scanner; public class Driver {

/** * The main keeps collecting bets from the user as long as he or she wants to * play. Total winnings are tracked and reported after each bet. * * @param args - Command line arguments. Not used. */ public static void main(String[] args) {

Scanner scan; String keepPlaying; double totalWinnings;

keepPlaying = "y"; totalWinnings = 0; scan = new Scanner(System.in);

System.out.println("Welcome to Chuck-a-luck!");

while (keepPlaying.equals("y")) { totalWinnings += oneBet(scan); System.out.printf("Your total winnings are $%,.2f ", totalWinnings); System.out.printf("Play again? (y) "); keepPlaying = scan.nextLine(); }

System.out.println("Thanks for playing!"); }

/** * Prompt the user for an integer value and return the result. * * @param prompt The prompt to display * @param scan An initialized scanner object * @return The int value entered by the user */ public static int readInt(String prompt, Scanner scan) { int input; System.out.print(prompt); input = scan.nextInt(); scan.nextLine(); return input; }

/** * Handle one betting interaction with the user. This method will ask the * user what bet they want to place, and how much they want to wager. * * @param scan - Initialized scanner object * @return Amount that the player won or lost on the bet */ public static double oneBet(Scanner scan) { Dice dice; dice = new Dice(); int betType; int number; String betPrompt; double betAmount; double payout;

number = -1; // This will be ignored unless the bet is SINGLE

betPrompt = " What is your bet? " + ChuckALuck.SINGLE + "- Single " + ChuckALuck.TRIPLE + "- Triple " + ChuckALuck.BIG + "- Big " + ChuckALuck.SMALL + "- Small " + ChuckALuck.FIELD + "- Field " + "Bet: ";

betType = readInt(betPrompt, scan);

if (betType == ChuckALuck.SINGLE) { number = readInt("Which number will you bet? (1-6) ", scan); }

System.out.print("How much do you want to bet? "); betAmount = scan.nextDouble(); scan.nextLine();

System.out.println("You rolled: " + dice.getFirst() + " " + dice.getSecond() + " " + dice.getThird());

payout = ChuckALuck.calculatePayout(dice, betType, number, betAmount);

if (payout

return payout; }

}

Chuck-a-luck is a betting game played with three dice. The player puts his or her money down orn one of the possible bets, then the dealer rolls the dice. The player collects a payout if the outcome matches the bet. The following table describes the possible bets Type Bet Odds 1 dice, 1 to 1 2 dice, 2 to 1 3 dice, 10 to 1 Single A specific number will appear on at least one die Any of the triples (all three dice show the same number) Any Triple Big 30 to 1 appeanr The total score will be 11 or higher with the exception of a triple The total score will be 10 or lower with the exception of a triple The total score will be outside the range of 8 to 12 (inclusive) 1 to 1 Small 1 to 1 Field 1 to 1 The final column in the table describes the payout if the player wins the corresponding bet. For example, if a player puts $5 down on single 3, and roll is [3, 3, 2], the payout will be $10 because the odds for that outcome are 2 to 1. If the dice rolled are [3, 3, 3], then the payout will be $50, because the odds for that outcome are 10 to 1 Your goal for this assignment is to develop and test a method for determining payouts in Chuck-a- luck Chuck-a-luck is a betting game played with three dice. The player puts his or her money down orn one of the possible bets, then the dealer rolls the dice. The player collects a payout if the outcome matches the bet. The following table describes the possible bets Type Bet Odds 1 dice, 1 to 1 2 dice, 2 to 1 3 dice, 10 to 1 Single A specific number will appear on at least one die Any of the triples (all three dice show the same number) Any Triple Big 30 to 1 appeanr The total score will be 11 or higher with the exception of a triple The total score will be 10 or lower with the exception of a triple The total score will be outside the range of 8 to 12 (inclusive) 1 to 1 Small 1 to 1 Field 1 to 1 The final column in the table describes the payout if the player wins the corresponding bet. For example, if a player puts $5 down on single 3, and roll is [3, 3, 2], the payout will be $10 because the odds for that outcome are 2 to 1. If the dice rolled are [3, 3, 3], then the payout will be $50, because the odds for that outcome are 10 to 1 Your goal for this assignment is to develop and test a method for determining payouts in Chuck-a- luck

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!