In your basic numbers game, players make either a “Straight” bet or a “Box” bet
ID: 3683378 • Letter: I
Question
In your basic numbers game, players make either a “Straight” bet or a “Box” bet with a 3-digit number. The winning combination is chosen at random. If the player’s number matches the winning number in any of the following ways, then the player wins the amount indicated, otherwise they lose. Type of Bet Description If your number is: Winning Numbers Payout Actual Odds Straight Exact order match 546 546 $600 to 1 1 in 1000 Box Match Any Order (3 different numbers) 546 546,564, 654,645, 456,465 $100 to 1 1 in 167 Match Any Order (1 duplicate number) 919 199,919,991 $200 to 1 1 in 333 Payouts shown are for the extinct, mob-run numbers game. Strange, but the payouts in the legalized, state-run games (e.g. “Cash 3”) are substantially lower. Note that there is only 1 way to win a straight bet but 6 different ways to win a box bet with 3 different numbers and 3 ways to win a box bet with 1 duplicate number This assignment is to create a class to simulate the numbers game. Your class will have 4 instance variables that store the bet type, bet amount, player’s number, and winning number, and a constructor to initialize them to values passed by the user. You may also have any additional instance variables you find necessary or useful. All instance variables must be type int, except for the bet type. Your class will also have two additional methods: 1. a method that returns the input data as a string 2. a method that compares the player’s number to the winning number and returns the amount won (or 0 if the player loses) All data are to be entered by the user. Output must include all the input values and must be neatly presented. Your program 6 times using this data: • Straight bet, $1, player number 123, winning number 123 • Straight bet, $1, player number 123, winning number 321 • Box bet, $1, player number 123, winning number 123 • Box bet, $1, player number 123, winning number 322 • Box bet, $1, player number 484, winning number 748 • Box bet, $1, player number 808, winning number 880. I am stuck creating the second method for the numbers class. Any help would be greatly appreciated.
Explanation / Answer
import java.util.*;
import java.util.Random;
class number_game
{
int bet_amt, play_no, win_no;
String bet_ty;
number_game(String bt, int bamt, int pno, int wno)
{
bet_ty=bt;
bet_amt=bamt;
play_no=pno;
win_no=wno;
}
int comp()
{
int a,a1,b,b1,c,c1;
if(bet_ty.equals("Straight bet"))
{
if(play_no==win_no)
{
return 600;
}
else
{
return 0;
}
}
else
{
a=play_no%10;
a1=win_no%10;
play_no=play_no/10;
win_no=win_no/10;
b=play_no%10;
b1=win_no%10;
play_no=play_no/10;
win_no=win_no/10;
c=play_no%10;
c1=win_no%10;
play_no=play_no/10;
win_no=win_no/10;
if((a==a1 && b==b1 && c==c1 ) || (a==b1 && b==a1 && c==c1) || (a==c1 && b==a1 && c==b1) )
return 200;
else
return 0;
}
}
}
class number_gametest
{
public static void main(String args[])
{
Scanner scan=new Scanner(System.in);
Random r = new Random();
System.out.println("Enter Bet type");
String bt=scan.nextLine();
System.out.println("Enter Bet amt");
int bamt=scan.nextInt();
System.out.println("Enter play number");
int pno=scan.nextInt();
int wno=r.nextInt(900)+100;
number_game o= new number_game(bt, bamt, pno, wno);
int wamt=o.comp();
System.out.println(bt+", $"+bamt+"player number "+pno+", winning number"+wno);
}
}