betOnce
Category: Programming
Author: Stuart Reges
Book Chapter: 5.4
Problem: betOnce
Write a method betOnce that takes a console Scanner and an integer as parameters and that allows the user to make a bet about the integer. The bet involves guessing whether a number between 1 and 36 is in the lower half of the range (1 through 18) or the upper half of the range (19 through 36). It will also be possible for the number to be 0, in which case the user always loses. These rules are used in a game called Roulette. Your method will be passed a Scanner that can be used to read input from the user and it will be passed the number that the user is betting on. For example, the main method might look like this: Scanner console = new Scanner(System.in); Random r = new Random(); int number = r.nextInt(37); betOnce(console, number); Your method should prompt the user for which bet they want to make and should then report the number and whether the user won or lost. For example, below is a log of execution where the user enters "1" to bet on the low range: Do you want to bet on 1) low or 2) high? 1 The number was 1 You win Below is a log where the user enters "2" to bet on the high range: Do you want to bet on 1) low or 2) high? 2 The number was 11 You lose Your method must exactly reproduce the format of these logs. You may assume that your method is always passed a number between 0 and 36. Remember that the user always loses when the number is 0. Write your solution to betOnce below.