Question
[Java] Implement the SlotMachine class according to the UML diagram below. Have a look at the slides or the book if you don t remember
[Java]
Implement the SlotMachine class according to the UML diagram below. Have a look at the slides or the book if you don t remember how to read the UML. Underlined fields or methods in a UML, specify that they are static. The two fields numPlayerWins and numHou seWins are both static and act as counters to keep track of wins
+ numPlayerWins : int
+ numHouseWins : int
-reels : int[][]
-gambleMachine(): void
+ isWinner(): boolean
+ SlotMachine()
The method gambleMachine will populate reels , which is a 3x3 array. Populate the array using the random number generator . Use numbers in the range between 1 and 9, including 9. The method isWinner will check if any of the three rows have the same values, it will also check if the one of the two diagonals has the same values. If any of the rows or the diagonals have the same numbers, it will return true , otherwise it will return false . The non - default constructor just calls the method gambleMachine..
The Casino class will just have the main method . In the main method create an array of type SlotMachine of size 1,000,000. Using a for - loop create objects of type SlotMachine and populate the array.Inside of the same for loop
check if the slot is a winner, if it is than increment the field numPlayerWins . If the slot is not a winner than increment the field numHouseWins . As you c reate objects of type SlotMachine the invoked constructor will call the method gambleMachine automatically, all you have to do is call the method isWinner on each object. After the for loop print out the number of times the casino has won and the number of times that the player has won. Also calculate and print out the chance of the player winning overall ( numbersWon/totalNumbersPlayed). Keep in mind,static fields can be calleddirectly on the class name (SlotMachine) . All of the instances of SlotMachine will share the same values for the fields numPlayerWins and numHouseWin.This is because they are static, and they belong to the clas s and not any specific instance of that class.
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