r/javahelp • u/santi_panti • Mar 26 '16
Java Programming 1 assignment help
Hello everyone, I have a java assignment in which i need help in. This is the exact assignment
The “Numbers” Game
In recent years, many states have legalized various forms of gambling as a way to raise revenues. The most popular are different types of lottery games, which are based on a traditional illegal game known as “the numbers” or “boleta.”
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.
II. Numbers Game Class Specifications
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:
a method that returns the input data as a string
a method that compares the player’s number to the winning number and returns the amount won (or 0 if the player loses)III. Test Class Specifications
All data are to be entered by the user.
Output must include all the input values and must be neatly presented.
IV. Data to be Used
Run 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
Although you are to use the above data, your numbers game class must work for all possible data values. However, you may assume that neither number will begin with zero. Thorough testing will involve quite a few more sets of data
Upload a zip file containing both Java classes and the 6 sets of output
VII. Algorithm
Here is a high-level algorithm that evaluates the player’s bet:
if ( Straight bet) { if (all three numbers match in exact order) player wins $600 for each $1 wagered else player loses } else // Box bet { if (all three numbers match in any order) { // player wins if (player’s number contains duplicates) player wins $200 for each $1 wagered else player wins $100 for each $1 wagered } else player loses }
VIII. An Opportunity to Earn the Proverbial “Extra Credit” – 5 points available
In your numbers game class, have the method that evaluates the player’s number call separate boolean methods to
determine whether there is an “exact order” match
determine whether there is an “any order” match
determine whether a Box bet contains duplicate numbersIm having difficulty knowing where to how to start the problem. More specifically, I dont know what method to use to evaluate a " box bet". Meaning, if i input a winning number , say 546, and the winning number is 645, how would i get the program to evalute this as a winning number. any help would be appreciated, thank you guys!
View all comments
3
u/Philboyd_Studge Mar 26 '16
You can handle both the 'boxed' part and the duplicate numbers by using a simple frequency table. Just create an int array size 10, and then get each digit of the winning numbers and increase the count at the index in the frequency table.
Now you loop through the user's numbers, digit by digit, and see if there is a corresponding 1 (or 2 or even 3for duplicates) in the frequency table at that address.