Your job is to create the Roulette class to interact with the Casino class to al
ID: 3660119 • Letter: Y
Question
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) The user should be prompted to place their bet on 1) Low or 2) High or 3) a Number If the user selected 3) a Number, prompt the user to enter a guess between 1 and 36. If the user selected 1) Low: And the number is between 1 & 18, the user wins and doubles their bet And the number is between 19 & 36, the user loses their bet And the number is 0, the user loses If the user selected 2) High: And the number is between 1 & 18, the user loses their best And the number is between 19 & 36, the user wins and doubles their bet And the number is 0, the user loses If the user selected 3) a Number and entered their guess: And the user guess matches the random number, they win 35 times their bet And the user guess does not match the random number, they lose their bet And the number is 0, the user loses Return the users winnings/losses to the console from the betOnce method and write/append the results to a text file named results.txt.Explanation / Answer
import java.awt.*; public class Roulette extends EasyApp { public static void main(String[] args) { new Roulette(); } Label lMoney = addLabel("Money",40,40,60,30,this); TextField tMoney = addTextField("",100,40,100,30,this); Button bBet = addButton("Bet",40,70,80,30,this); Button bSpin = addButton("Spin",120,70,80,30,this); TextField tBet = addTextField("",40,100,80,40,this); TextField tChoice = addTextField("",40,140,80,40,this); TextField tNumber = addTextField("",120,100,80,80,this); int money = 1000; int bet = 0; int betting = 0; String choice = ""; public void actions(Object source,String command) { if(source == bBet) { makeBet(); } else if (source == bSpin) { spin(); } } public Roulette() { setTitle("Raging Roulette"); setSize(250,200); setBackground(Color.green); tNumber.setFont(new Font("Arial",0,50)); tNumber.setForeground(Color.white); tNumber.setBackground(Color.green); tBet.setFont(new Font("Arial",0,30)); tChoice.setFont(new Font("Arial",0,30)); tMoney.setFont(new Font("Arial",0,16)); tMoney.setText(money + ""); } public void makeBet() { do { betting = inputInt("How much do you want to bet?"); } while (betting < 0 || betting > money); bet = betting; choice = input("Betting on : Red, Black, or a Number"); tBet.setText(betting + ""); tChoice.setText(choice); } public int rand(int lowest, int highest) { return (int)(Math.floor(Math.random()*(highest-lowest+1)+lowest)); } public void spin() { long start = System.currentTimeMillis(); do { int num = rand(0,36); tNumber.setText( num + ""); if (num == 0) { tNumber.setBackground(Color.green); } else if ( ((num-1)/3) % 2 == 0 ) { tNumber.setBackground(Color.red); } else { tNumber.setBackground(Color.black); } repaint(); } while (System.currentTimeMillis()-start < 3000); money = money + checkWinner(); tMoney.setText(money + ""); } public int checkWinner() { if ((tNumber.getBackground() == Color.red) && (tChoice.getText().equals("Red"))) { return bet; } else if ((tNumber.getBackground() == Color.black) && (tChoice.getText().equals("Black"))) { return bet; } else if (tNumber.getText().equals( tChoice.getText() ) ) { return 36*bet; } else { return -bet; } } public void pause(long millis) { long start = System.currentTimeMillis(); do { } while (System.currentTimeMillis() - startRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.