Question: Write a java application program that simulates a simple slot machine in which three numbers between 0 and 9 are randomly selected and printed side
Write a java application program that simulates a simple slot machine in which three numbers between 0 and 9 are randomly selected and printed side by side. The program will allow the user to place a bet, and then make a payout if any two of the numbers are the same, or if all three numbers are the same.
Program Requirements:
Follow the formatting that you see in the example program. Space out items with extra line breaks for neatness and ease of reading.
All money values that are printed to the screen should be preceeded by a dollar sign, and should be formatted to display two decimal places.
The starting balance should be stored as a constant in your program and NOT as a variable. It should be declared at the beginning of the main program so it can be found easily. This allows it to be easily modified if we ever decided to change the starting balance. The dollar amount of $10 should ONLY be used ONCE in your program, at the time you are initializing the constant.
Due to the impreciseness of double and float data types, you are NOT ALLOWED to use any double or float variables anywhere in your program. All money values should be stored as integers. Note that a money value can be accurately represented as a whole number by considering the number of pennies in the money value. For example, $1.58 is equivalent to 158 pennies. You can read the user input into your program by using nextDouble(), but you must immediately convert it, and store it, as an integer. Likewise, when printing the dollar amounts to the screen, you need to convert back, and print as a double with two decimal places using printf().
To calculate the winnings:If all three numbers on the slot machine are the same, then
Add 1 to the number on the slot, and then multiply it by the amount of the bet
As an example, if the number shown on all three slots is 4, and the user has bet $2.00, then the winnings would be $10.00. (4 + 1) * $2.00
If any two numbers on the slot machine are the same, then
Multiply the matching number by the amount of the bet and then divide by 2.
As an example, if the number shown on two of the slots is 7, and the user has bet $1.00, then the winnings would be $3.50. 7 * $1.00 / 2
As another example, if the number shown on two of the slots is 2, and the user has bet $3.00, then the user breaks even as the winnings would be $3.00. 2 * $3.00 / 2
As another example, if the number shown on two of the slots is 1, and the user has bet $4.25, then the user gets half of their money back as the winnings would be $2.12. 1 * $4.25 / 2 Note that the answer to this calculation actually is $2.125 but we will not be rounding up. We will simply discard the 0.005 portion of the answer. If all money values in your program are being treated as integers, then this will already be done automatically for you.
As another example, if the number shown on two of the slots is 0, and the user has bet $2.50, then there are no winnings. (0 * $2.50 / 2 produces an answer of 0)
If all three numbers on the slot machine are different, then there are no winnings.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
