Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3529411 • Letter: F

Question

 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 (totalling 8 or higher), Low (totalling 6 or less) or Sevens (totalling exactly 7).  If the player wins, he receives a payout based on the schedule given in the table below:

Choice
Payout
High
1 x Wager
Low
1 x Wager
Sevens
4 x Wager

The player will start with $100 for wagering. If the player chooses to wager $0 or if he runs out of money, the program should end. Otherwise it should ask him whether he's wagering on High, Low or Sevens, display the results of the die rolls, and update his money total accordingly.

For this assignment you should start with the following "skeleton" of Java code. Import this into your Eclipse workspace and fill in the methods as directed:
 
 
 import java.util.Scanner;   public class Project07 {           public static void main(String[] args) {                 // Fill in the body         }                           // Given a Scanner and a current maximum amount of money, prompt the user for         // an integer representing the number of dollars that they want to bet.  This         // number must be between 0 and to maximum number of dollars.  If the user enters         // a number that is out of bounds, display an error message and ask again.         // Return the bet to the calling program.         private static int getBet(Scanner inScanner, int currentPool) {                 // Fill in the body         }                  // Given a Scanner, prompt the user for a single character indicating whether they         // would like to bet High ('H'), Low ('L') or Sevens ('S').  Your code should accept         // either capital or lowercase answers, but should display an error if the user attempts         // to enter anything but one of these 3 values and prompt for a valid answer.         // Return the character to the calling program.         private static char getHighLow(Scanner inScanner) {                 // Fill in the body         }                  // Produce a random roll of a single six-sided die and return that value to the calling         // program         private static int getRoll() {                 // Fill in the body         }                  // Given the choice of high, low or sevens, the player's bet and the total result of         // the roll of the dice, determine how much the player has won.  If the player loses         // the bet then winnings should be negative.  If the player wins, the winnings should         // be equal to the bet if the choice is High or Low and 4 times the bet if the choice         // was Sevens.  Return the winnings to the calling program.         private static int determineWinnings(char highLow, int bet, int roll) {                 // Fill in the body         }  } 
 
 
 
 some sample output: 
 You have 100 dollars.
Enter an amount to bet (0 to quit): 50
High, low or sevens (H/L/S): H
Die 1 rolls: 1
Die 2 rolls: 5
Total of two dice is: 6
You lost!

You have 50 dollars.
Enter an amount to bet (0 to quit): 25
High, low or sevens (H/L/S): L
Die 1 rolls: 6
Die 2 rolls: 2
Total of two dice is: 8
You lost!

You have 25 dollars.
Enter an amount to bet (0 to quit): 12
High, low or sevens (H/L/S): H
Die 1 rolls: 2
Die 2 rolls: 6
Total of two dice is: 8
You won 12 dollars!
 
Choice
Payout
High
1 x Wager
Low
1 x Wager
Sevens
4 x Wager

Explanation / Answer

import java.util.Scanner;


public class Project07 {


public static void main(String[] args) {
int amount = 100, roll1,roll2;
int bet;
char c;
int lost_or_win;
Scanner in = new Scanner(System.in);
do
{
if(amount == 0 || amount < 0) break;
System.out.println(" You have " + amount + " dollars ");
bet = getBet(in, amount);
if(bet == 0) break;

c = getHighLow(in);
roll1 = getRoll();
System.out.println(" Die 1 rolls : "+ roll1);
roll2 = getRoll();
System.out.println(" Die 2 rolls : "+ roll2);
System.out.println("Total of two dice is: " + (roll1+ roll2));
lost_or_win = determineWinnings(c,bet, roll1+ roll2);
if(lost_or_win < 0)
System.out.println("You lost!");
else
System.out.println("You won " + lost_or_win + " dollars! ");
amount = amount + lost_or_win;
System.out.println("");
System.out.println("");
}while(true);

}

private static int getBet(Scanner inScanner, int currentPool) {
System.out.println("Enter an amount to bet (0 to quit): ");
int result = inScanner.nextInt();
if(result > currentPool)
{
do
{
System.out.println(" u dont have " + result + " to bet !! ");
System.out.println("Enter an amount to bet (0 to quit): ");
result = inScanner.nextInt();
}while(result > currentPool);
}
return result;
}

private static char getHighLow(Scanner inScanner) {
System.out.println("High, low or sevens (H/L/S): ");
String str = inScanner.next();
return str.charAt(0);
}

private static int getRoll() {
return (int)(Math.random()*6) + 1;
}

private static int determineWinnings(char highLow, int bet, int roll) {
int result = 0;
if(highLow == 'H')
{
if(roll < 7)
{
result = -1*bet;
}
else
{
result = bet;
}
}
if(highLow == 'L')
{
if(roll > 7)
{
result = -1*bet;
}
else
{
result = bet;
}
}
if(highLow == 'S')
{
if(roll == 7)
{
result = 4*bet;
}
else
{
result = -1*bet;
}
}
return result;
}

}










Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote