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

Please help!! im struggling with this project!! For this lab you will write a Ja

ID: 673821 • Letter: P

Question

Please help!! im struggling with this project!!

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:


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 must start with the following "skeleton" of Java code. Import this into your Eclipse workspace and fill in the methods as directed:

Project07.java**

Project 07 Sample Output

This is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen by your program.

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!

You have 37 dollars.
Enter an amount to bet (0 to quit): 18
High, low or sevens (H/L/S): S
Die 1 rolls: 5
Die 2 rolls: 4
Total of two dice is: 9
You lost!

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

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

You have 15 dollars.
Enter an amount to bet (0 to quit): 7
High, low or sevens (H/L/S): H
Die 1 rolls: 5
Die 2 rolls: 6
Total of two dice is: 11
You won 7 dollars!

You have 22 dollars.
Enter an amount to bet (0 to quit): 0

You have 22 dollars left
Goodbye!


Note that your output depends on the choices made by the user. Remember to check that the user's inputs are valid:

You have 100 dollars.
Enter an amount to bet (0 to quit): -100
Your bet MUST be between 0 and 100 dollars
You have 100 dollars.
Enter an amount to bet (0 to quit): 1000
Your bet MUST be between 0 and 100 dollars
You have 100 dollars.
Enter an amount to bet (0 to quit): 100
High, low or sevens (H/L/S): h
Die 1 rolls: 2
Die 2 rolls: 6
Total of two dice is: 8
You won 100 dollars!

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

You have 0 dollars left
Goodbye!

**

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

Explanation / Answer


/*
* Project07.java
*
* A program that plays the dice game high/low
* Used to practice breaking code up into methods.
*
* @author ENTER YOUR NAME HERE
*
*/
//package osu.cse1223;
import java.io.*;
import java.util.Scanner;


public class LuckySeven {


public static void main(String[] args) {
// Fill in the body
Scanner inScanner = new Scanner(System.in);
int currentPool = 100;
int bet = 1, roll, die1, die2, winnings;
char highLow;
while(currentPool != 0 || bet != 0)
{
System.out.println("You have "+currentPool+" dollars.");
bet = getBet(inScanner, currentPool);
if(bet == 0)
{
break;
}
highLow = getHighLow(inScanner);
die1 = getRoll();
die2 = getRoll();
roll = die1 + die2;
System.out.println("Die 1 rolls: "+die1);
System.out.println("Die 1 rolls: "+die2);
System.out.println("Total of two dice is: "+roll);
winnings = determineWinnings(highLow, bet, roll);
if(winnings < 0)
{
System.out.println("You lost!");
currentPool -= bet;
if(currentPool == 0)
break;
}
else
{
System.out.println("You won "+winnings+" dollars!");
currentPool += winnings;
}
}
System.out.println("You have "+currentPool+" dollars left. Goodbye!");
}
  
  
// 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
int bet = -1;
while(bet < 0 || bet > currentPool)
{
System.out.print("Enter an amount to bet (0 to quit): ");
bet = inScanner.nextInt();
if(bet < 0 && bet > currentPool)
System.out.println("Your bet MUST be between 0 and "+currentPool+" dollars");
}
return bet;
}
  
// 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
char highLow = ' ';
while(highLow != 'H' && highLow != 'L' && highLow != 'S')
{
System.out.print("High, low or sevens (H/L/S): ");
highLow = inScanner.next().charAt(0);
if(Character.isLowerCase(highLow))
highLow = Character.toUpperCase(highLow);
if(highLow != 'H' && highLow != 'L' && highLow != 'S')
System.out.println("Invalid Choice. Please follow the prompt.");
}
return highLow;
  
}
  
// 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
int randomNum = 1 + (int)(Math.random() * 6);
return randomNum;
}
  
// 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
if(roll < 7 && highLow == 'L')
return bet;
else if(roll > 7 && highLow == 'H')
return bet;
else if(roll == 7 && highLow == 'S')
return 4*bet;
else
return -bet;   

}

}