Java Program That Implements Slot Machine Application
Design a solution: The design of my system should be consistent with the Object Oriented principles and easy to understand by an independent programmer.
Problem description and requirement statement
I need a Java program that implements a Slot Machine application. In my GUI application I should be able to resize the window of my application keeping the component in the same “relative” position.
Winning or Losing the game: In the reel can appear one of six different symbols. I have attached the images in the images folder. To win a game, the symbols on two or all three reels must be the same when the reels are stopped. The payout in credits for each of the symbols is as follows.
- Seven: 7
- Bell: 6
- Watermelon: 5
- Plum: 4
- Lemon: 3
- Cherry: 2
So, for example, say you start the game and you have your initial 10 credits. You bet 3 credits, so you now have 7 credits (your bet was deposited in the machine). You spin the reels, and when they stop, they are all watermelons. You have won 15 credits (the 3 you bet multiplied by the 5 credits that a watermelon is worth). The 15 credits are then added to your 7 credits, giving you a total of 22 credits. When none of the reels match, you lose. The credits that you bet are left in the machine.
Specifications: The GUI has to present the following graphical component
- An “Add coin” button: this lets the user to add a coin to the credit
- A “Credit Area”: this informs the user of the number of credits that he/she has left to play with. Note that you can’t continue to play with no credits. When you begin the program, you are given 10 free credits.
- A “Bet One” button: This allows the user to bet a single credit.
- A “Bet Max” button: This allows the user to add a maximum number of credits in the bet. The maximum number of credits is permanently set to 3. This button is just a convenience, as you may add more credits if you like by clicking the “Bet One” button.
- A “Reset” button. This allows the user to return the amount that he/she has bet to the credits that he/she still has.
- A “Spin” button. This causes the three reels to spin.
- A “Bet area”. This informs the user of the number of credits that he/she is betting on the current game.
- Three reels. When the Spin button is clicked, all three reels will begin to spin. To stop the reels from spinning, you can simply click on any of them.
- “Statistics” button: This allows the user to check his/her number of wins, losses, and the average number of credits that she/he has netted per game. If the average is positive, then the player has been, on average, winning more credits than losing. If it is negative, then the player has been, on average, losing more credits than winning.
A game is over after all three reels have been clicked and have stopped spinning. The results of the game will be displayed. Note that you cannot play if your credit is zero or if your bet is zero.
1) Create an interface ISymbol, which contains the following methods:
- setImage(…), which sets the image associated with one of the symbols in a reel, represented by the Symbol class implementing the interface.
- getImage(), which return the image.
- setValue(int v) which sets the value of the symbol as defined above.
- getValue(), which returns the value of the symbol.
2) Create a class Symbol, which represents one of the symbols in a reel and implements the ISymbol interface.
3) Design and implement a class Reel which contains a list of 6 instances of Symbol objects each one of them having a different value (implement the 6 symbols defined above). The class should include a method spin() which returns the list with the six symbol. The array should be randomly populated and the position of the symbols should change every time a new reel is created.
You must use one of the API container class to hold the three reels.
The class may contain any additional methods that you choose as appropriate and necessary for the rest of your game application. The Slot Machine GUI application has to follow the requirements below:
5) Press the “Add Coin” button to add one coin to the credit. Every time the game starts the initial credit is 10. (e.g. If you want credit equal 15 you need to press five times the “Add Coin” button).
6) Display a “Credit Area” where the user can visualize the current credit. Note that you cannot continue to play with no credits. When you begin the program, you are given 10 free credits. If the user tries to play with no credit the application will show a warning message.
7) Display a “Bet area” to inform the user of the number of credits that he/she is betting on the current game.
8) Pressing the “Bet One” button the user bet a single credit. The number in the bet area is incremented by one.
9) Pressing “Bet Max” button the user adds a maximum number of credits to the bet. The maximum number of credits is permanently set to 3. This button is just a convenience, as you may add more credits if you like by clicking the “Bet One” button.
10) Implement a “Reset” button to allow the user to return the amount that he/she has bet to the credits area.
11) Pressing the “Spin button” each reel will show a new symbol, selected randomly among the 6 symbols above.
12) If two or three symbols in the three reels are the same the game is won. Compute the amount of money that are won and add them to the credit. Implement a method in the class Symbol to compare two symbols. If the user lost the game (three different symbols) the amount bet is lost and the bet area displays zero.
13) Modify the implementation in section 11) when the user press the “Spin” button. When the button is pressed the three reels start to spin. In each reel the images of the 6 symbols are visualized continually simulating a real spinning behavior. That means that once the reel starts to spin you will see appearing in sequence all the six symbol. The three reels are spinning at the same time but they show different random sequence of symbols. Implement the spinning in three different threads.
14) When the Spin button is clicked, all three reels will begin to spin. To stop a reel from spinning, simply click on one of them. (To stop the threads, do not use the stop method, which has been deprecated.)
15) Display the message “You win!” and the amount of money won, when the user win, or “You lose” if the user lost the game.
16) Pressing “Statistics button” a new window will be opened. In this window the user can check the wins, losses, and the average number of credits that he/she has netted per game. You can choose how to visualize this information in the windows. Write in the comment which graphical component you chose and explain the reason.
17) In the “Statistics Window” has to be a button call “Save statistics”. Pressing this button the statistics will be saved in a .txt file in the current path. The name of the file has to be the current date/time.
18) Analyzing the winning combinations, model the slot machine in order to assure a payout of approximately 90%. Develop and implement the algorithm that computes the payout based on the model that you identified.