Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

/* * 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.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 } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago