You will make any necessary fixes to your SlotMachine class, then run it many times and gather some statistics.
Write a test driver for your working SlotMachine that spins it a million times and counts how many jackpots and pairs are spun.
If you need to make corrections to your slot machine class, the problem description, with added notes, is at the bottom of this page.
Currently you have a driver that spins your slot machine until a jackpot is spun. You print the slot machine after each spin. If your driver works, then you know you spun at least one jackpot.
But now, let's look closer at how often your slot machine will produce a jackpot. Write a new driver which spins the jackpot a million times and counts the number of pairs and jackpots that were spun. You will compare your results to the mathematical odds of spinning jackpots and pairs.
Assuming 3 slots with 7 possibilities for each slot, for 1 million spins:
expected pairs: 367346.94 expected jackpots: 20408.16
Does your slot machine come close to that? How close?
Computers are fast. You can spin your slot machine a million times in under a second. But, you can't print it a million times in under a second. I/O, or Input/Output, takes a lot of time. As you develop your driver, you probably want to run it a smaller number of times, i.e. 100, printing each spin. Once you think it is working correctly, remove the print statement and run it a million times, and just print the results (counts of pairs and jackpots).
How close are your results to the mathematical results? How does that change if you raise or lower the number or trials run?
Submit your SlotMachine.java and your test driver (whatever you called it) to the Lab Submission Folder on D2L.
Write a class called SlotMachine representing a simple slot machine.
Your slot machine will have 3 slots (integers) which are only accessible from within the class.
The constructor will create a new instance of the class with three randomly generated slots in the range [0,6]. (Remember to import java.util.Random at the top of your class.) The constructor has NO parameters because the data in this class is randomly generated.
There are no getters or setters for this class. There are no getters and setters because they are not needed. Think about a real slot machine - should you be able to set one of the slots manually? No! The only way you can change the state of the slot machine is to spin it. Should you be able to "get" the value of slots individually? No - not necessary. The "display" (toString) of the machine shows you the value of all slots at the same time.
The spin method simulates the spinning of slot machine by randomly generating each slot. Each slot is in the range [0,6]. No parameters for this method! This method is a void method. It's purpose is to change the state of the slot machine.
The isJackpot method answers if the slot machine is showing a jackpot, in other words, all three slots are the same. This is a boolean method.
The isPair method answers if the slot machine is showing a pair, i.e. two slots are the same, but the other one is different. This is also known as Two of a Kind. This is a boolean method.
The toString method formats the slot machine as a String. It needs to contain the current value of each "slot".
Write a driver which creates a SlotMachine and spins it until a jackpot is spun. Print the slot machine after each spin. For every spin, call the isPair method and print a message if there is a pair. Print a jackpot message when a jackpot is spun.
The driver should also count how many spins it took until a jackpot was spun, and print that out at the end. The driver does all the printing. The SlotMachine class does NO printing.