You will use the Casino.java (that is provided) to drive the Roulette class (tha
ID: 3533569 • Letter: Y
Question
You will use the Casino.java (that is provided) to drive the Roulette class (that you will create).
Here is the code for the Casino.java
import java.util.*;
public class Casino {
public static void main (String[] args) {
Scanner console = new Scanner (System.in);
double wallet = 100.00; //Start the user off with $100
double bet = 0.00; //User bet
double result = 0.00; //To store the winnings/losses of each game
String input = ""; //User input
//Create instance of the Roulette game (that you're creating)
Roulette game = new Roulette();
do {
System.out.println("How much would you like to bet?");
bet = console.nextDouble();
wallet = wallet - bet;
//Play a round and store the results
result = game.betOnce(bet);
//Flush the buffer
console.nextLine();
//Update wallet amount and notify user
wallet = wallet + result;
System.out.println("You have $" + wallet + " in your wallet.");
System.out.println("Bet again? Y or N?");
input = console.nextLine();
} while (!input.equalsIgnoreCase("N"));
} //end main
} //end class
Your job is to create the Roulette class to interact with the Casino class to allow the user to play the game of Roulette.
Here are the rules:
Create a class named Roulette with a method named betOnce that takes, as parameters, the amount of the user bet.
Generate a random number between 0 and 36 (that simulates the wheel - must use Math.random and set the range so it will only return the roulette numbers 0-36)
The user should be prompted to place their bet on 1) Low or 2) High or 3) a Number
Use the swtich statement .
If the user selected 3) a Number, prompt the user to enter a guess between 1 and 36.
If the user selected
Explanation / Answer
please rate - thanks
ran out of time --if any problems let me know I'll fix after it's rated
import java.util.*;
public class Casino {
public static void main (String[] args) {
Scanner console = new Scanner (System.in);
double wallet = 100.00; //Start the user off with $100
double bet = 0.00; //User bet
double result = 0.00; //To store the winnings/losses of each game
String input = ""; //User input
//Create instance of the Roulette game (that you're creating)
Roulette game = new Roulette();
do {
System.out.println("How much would you like to bet?");
bet = console.nextDouble();
wallet = wallet - bet;
//Play a round and store the results
result = game.betOnce(bet);
//Flush the buffer
console.nextLine();
//Update wallet amount and notify user
wallet = wallet + result;
System.out.println("You have $" + wallet + " in your wallet.");
System.out.println("Bet again? Y or N?");
input = console.nextLine();
} while (!input.equalsIgnoreCase("N"));
} //end main
} //end class
---------------------------------------------------
import java.util.*;
public class Roulette
{public static double betOnce(double amount)
{int bet,n,number=0;
n = 0 + (int)(Math.random()*36);
Scanner console=new Scanner(System.in);
System.out.print("Do you want to bet on 1) low, 2) high, 3) a number? ");
bet=console.nextInt();
if(bet==3)
{System.out.print("Enter the number: ");
number=console.nextInt();
}
System.out.println("The number was "+n);
if(n==0)
{amount=0;
return amount;
}
if(bet==1)
if(n<19)
amount*=2;
else
amount=0;
else if(bet==2)
if(n>18)
amount*=2;
else
amount=0;
else
if(number==n)
amount*=35;
return amount;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.