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

Write a method named betOnce that takes a console Scanner and an integer as para

ID: 3625133 • Letter: W

Question

Write a method named 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.

Explanation / Answer

please rate - thanks

import java.util.*;
public class betOnce
{public static void main(String[] args) {
Scanner console = new Scanner(System.in);
Random r = new Random();
int number = r.nextInt(37);
betOnce(console, number);   
}
public static void betOnce(Scanner console,int n)
{int bet;
System.out.print("Do you want to bet on 1) low or 2) high? ");
bet=console.nextInt();
System.out.println("The number was "+n);
if(n==0)
   System.out.println("You lose");
else if(bet==1)
    if(n<19)
          System.out.println("You win");
    else
          System.out.println("You lose");
else
    if(n>18)
          System.out.println("You win");
    else
          System.out.println("You lose");
   

   

}                                 
    }
               

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