Question
Need help with this Java program, mostly the second part involving the three slot machines. Sorry it's so long, but I'm really stuck. Solve the
Need help with this Java program, mostly the second part involving the three slot machines. Sorry it's so long, but I'm really stuck.
Solve the problem first with one simple slot machine. It pays a jackpot of 2 quarters every 3rd play.
It will require a counter variable to keep track of how many times the machine has been played, and a variable which represents her bucket of quarters. Use some output statements that allow you to keep track of the behavior. Submit a copy of this introductory step, along with several test outputs.
Your program will input the number of quarters in Margeries jar, and the number of times the machine has been played since it last paid a jackpot.
Suppose you have one machine; it pays 2 quarters every 3rd play. Margerie has 4 quarters, and when she arrives the machine has never been played.
Your program output might look like this: (The debugging output statements can include any information that you find helpful. These will be commented out for the next program.)
This test case MUST work, and the answer must be 8.
How many quarters does Marge have in the jar? 4 How many times has the machine been played: 0 Lose 3 left Lose 2 left Win 3 left Lose 2 left Lose 1 left Win 2 left Lose 1 left Lose - 0 left Game over. Margerie played 8 times.
After you get the single machine to work correctly, paste it into this document, which you will submit, and begin to solve the problem with three slot machines.
After you have the easiest case working, its time to start on the more interesting case where Margerie plays 3 slot machines in sequence. You will ask the user how many times the slot machine has been played before Margerie arrived.
For example if a slot machine pays a jackpot every 100 plays, and someone else had been there and played 99 times, the machine will pay out the jackpot on the very first play.
Sample Input Data I for meeting the specification above. User input is the answers to these questions:
How many quarters does Marge have in the jar? 937 How many times has the first machine been played since paying a jackpot? 17 How many times has the second machine been played since paying a jackpot? 72 How many times has the third machine been played since paying a jackpot? 6 Marge played XXX times, but has run out of money.
Sample Input Data II for meeting the specification above.
How many quarters does Marge have in the jar? 2000 How many times has the first machine been played since paying a jackpot? 34 How many times has the second machine been played since paying a jackpot? 59 How many times has the third machine been played since paying a jackpot? 9 Marge plays XXX times
There is only one right answer for each data set, i.e. the machines are deterministic. That means that they behave consistently all the time. There are no random numbers, and there is no outside influence. If you run the program 100 times, you will get the same answer 100 times.
Hint: If she runs out of money playing the first slot machine, you should not allow her to play anymore.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started