Write a Java assignment that simulates the behavior of a Casino with three slot machines.
Motivation: Practice with the Object-Oriented concepts of inheritance and overriding.
Here are the rules for each machine
Machine A:
Cost of a game: 1 token
Number of reels: 4
Each reel can display a SUN or a MOON
The machine pays off 2 tokens if one and only one reel displays a sun
The machine pays off 100 tokens if ALL the reels display a sun
Machine B:
Cost of a game: 1 token
Number of reels: 3
Each reel can display an ORANGE, or a CHERRY, or a WATERMELON or a QUESTION MARK.
The machine pays off 500 dollars if ALL the reels display the same image: 3 oranges, 3 cherries, 3 watermelons, or 3 question marks.
The machine pays off 10 tokens if one and only one real displays a Question Mark.
The machine pays off 100 tokens if the reels display 1 Orange, 1 Cherry and 1 Watermelon.
Machine C
Cost of a game: 1 token
Number of reels: 4
Each reel can display the 10 numbers in the range: [0 .. 9]
The machine pays off 10 tokens if the reels display TWO identical digits ( Example 7078)
The machine pays off 100 tokens if the reels display THREE identical digits ( Example 4644)
The machine pays off 1000 tokens if the reels display THREE identical digits ( Example 5555)
Write a Java program that simulates the use of the slot-machines by a player.
Your program should define a class named SlotMachine, and three classes inherited class: SMA, SMB, and SMC, each overriding the method(s) of the super-class.
The player enters the Casino with 50 tokens.
Every time the player selects a machine (A, B or C) randomly.
The visit to the Casino ends when either the player’s reserve is 0 or at least 1000 tokens.
For each win, (not for a loss) display on one line:
- The sequence number of the attempt
- The machine type (A, B or C) that is paying
- The amount paid
- The configuration displayed
- The current amount of the player
Example: at #17 SMB paid 10 - Output: (Cherry, Cherry, Cherry) - Current player’s reserve: 41
Rubric:
- Define a superclass (variables and methods) à 1 point
- Define 3 sub-classes ( implementation of inheritance, and overriding ) à 15 points ( = 3 x 5)
- a loop à 1 point
- Select randomly the next machine à 1 point
- For each attempt, update the player’s reserve and if it is a win, display the current situation (See description above) à 1 point
- At the end of the player’s visit, display the total number of tokens used by the player à 1 point
NOTE: It looks like this program needs a robust random number generator (a static method). Robust means that it generates numbers that are really random.