Project 2 — UMBC Lucky Sevens Slot Machine
Assigned | Wednesday, February 29th |
---|---|
Program Due | Wednesday, March 14nd by 9:00am
Extended to Friday, March 16th by 9:00am |
Weight | 7% |
Updates | A new copy of Symbol.java can be found here. There was a problem with the exception throwing that has now been fixed. |
You can download Project2.java now |
Objectives
To gain experience in the following areas.
- Using composition in an object-oriented design
- Interfacing with code designed and implemented by someone else
- Using enumeration
- Writing unit tests
To continue to gain experience in the following areas.
- Documenting classes
- Documenting methods
Project Policy
This project is considered an OPEN project. Please review the open project policy before beginning your project.
In-class Project Analysis
Once this project is turned in, the code will be reviewed in class as noted on the schedule as “Project 2 Analysis.” If you would like to volunteer your code to be reviewed in class as part of the analysis, please contact your instructor. Your name will be held in strict confidence. This practice has worked extremely well in the past. It is a wonderful way to compare and contrast the different designs that people have used. And think about it -- you get personel (yet anonymous) feedback on your project by your instructor!
Project Overview and Design
UMBC has decided to create a slot machine program to supplement the budget of the Computer Science Department. That way, a number of the underpaid Lecturers can make competitive salaries.
The graphical user interface (GUI) code for the slot machine will be provided
for you as Project2.java
. Here's a
picture of the interface. Your job is to implement the functionality
of the machine. Specifically, you will implement a class named
SlotMachine
to represent the slot machine and a class named
Reel
to represent a reel (the machine has three of them) that
displays six possible symbols (a watermelon, an orange, a plum, a lemon, a
cherry, and the number 7). A class named Symbol
that represents
these symbols as an enumerated type and a file called images
that contains the symbol images will be provided for your use.
You can download and play the demo of the Lucky Seven Slot Machine. This will download an executable jar file that can be executed by double clicking on the p2.jar file.
Project Specification
Machine Components
The Lucky Sevens slot machine has the following eight graphical components.
- A "Bet One" button. This allows the user to bet a single credit.
- A "Bet Max" button. This allows the user to bet a maximum number of credits. 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.
- An information area. Information as to the status of the machine and the game just played are displayed in this area.
- A "Credits" area. This informs the user of the number of credits that he/she has left to play with. Note that you may continue to play with no credits. You just don't win anything. When you begin the program, you are given 10 free credits.
- A "Bet" area. This informs the user of the number of credits that he/she is betting on the current game. Note that you do not need to bet any credits (that is, Bet can be zero) to play the game. But, again, you won't win anything.
- Three reels. When the Spin button is clicked, all three reels will begin to spin. To stop a reel from spinning, simply click on it. It does not matter in what order you stop the reels.
A game is over after all three reels have been clicked and have stopped spinning. The results of the game will be displayed in the white information area.
Note that there are also three menus (Game, Admin, and Help) at the top of the screen. Their functions are as follows.
- Game allows the user to add more credits to play with.
- Admin 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 more credits than losing. If it is negative, then the player has been, on average, losing more credits than winning.
- Help provides help on how to play the Lucky Sevens slot machine.
Winning and Losing
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: 12
- watermelon: 10
- orange: 8
- plum: 6
- lemon: 4
- 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 oranges. You have won 24 credits (the 3 you bet multiplied by the 8 credits that an orange is worth). The 24 credits are then added to your 7 credits, giving you a total of 31 credits.
Or, you bet 3 credits, which are deposited in the machine, giving you 7 credits. You spin the reels, and when they stop, two of them are plums. You have won 9 credits (the 3 you bet multiplied by half of the 6 credits that a plum is worth). The 9 credits are then added to your 7 credits, giving you a total of 16 credits.
When none of the reels match, you lose. The number of credits that you bet are left in the machine.
Note that you can bet zero credits and still play the game. The information under the Admin menu item simply is not updated.
Project Hints, Notes, Requirements, Restrictions
- The Javadoc for the
SlotMachine
,Reel
andSymbol
classes can be found here. - The code for the
Symbol
class and theimages
are provided for you Project2.zip. You need to download this file onto your computer, wherever you like. Now, to create your project and automatically importSymbols
andimages
into your project, do the following.- Open Eclipse
- Select:
File
- A pop-up window should appear. Click on
Import ...
- Click on
Existing Projects into Workspace
, then clickNext
- Another pop-up window will appear. Click the button for Select
archive file:
- Click Browse and navigate to the Project2.zip file that you saved earlier
- Double-click on the Project2.zip file
- One last pop-up, Import Projects, will appear. Click Finish.
src
, you will see that theSymbol
class and theimages
file are there. You are now ready to add yourSlotMachine
andReel
classes. - The code for the
Project2
class will be posted in in about a week. But you can begin coding NOW, as you have the Javadoc for the two classes that you are responsible for implementing. - You must use an array object to hold the three reels. Do not use any of the API container classes, such as ArrayList. That will be allowed later in the semester.
- When the SlotMachine constructor is called from the Project1 class' main method, it will be passed a "random number seed" (we'll discuss this in class). Use this seed to randomly populate each of the slot machine's three reels with the six symbols. Right now, the seed value is set to 10 by the Project1 class. So, when you test your code before you have the Project1 class code, be sure to test it with a seed of 10. Begin with the left-most reel and move to the right. Increment the seed by one as you move from left to right. That is, the left-most reel gets a seed of 10, the next a seed of 11, and the last a seed of 12. BUT your code should NOT use these literal values! Think about it -- what would happen to your code if the seed value in the Project1 class were changed?
- You must comment using Javadoc formatting for both function and class headers.
-
All methods of the
SlotMachine
andReel
classes must have appropriate method header comments, including pre- and post-conditions, as shown in the course coding standards and discussed in class. - You must make sure that no method preconditions are violated. We will be testing your program with a text-based interface, so we will be able to violate your method preconditions!
-
Both the
SlotMachine
andReel
classes should have file header comments, including class invariants. -
You must thoroughly unit test the
isWinner
method in theSlotMachine
class. For this project, you do not need to unit test any other methods.
Grading
See the course website for a description of how your project will be graded.
Project Compilation and Submission
Before submitting your project, be sure to compile and test your code on the
GL system. As you will be using a GUI as the interface for this project, you
must test your code using Eclipse on one of the UMBC lab
machines. You cannot run your code on the GL
system remotely (i.e. using your computer). So,
transfer your code to the GL system, import all of your files (Project2.java,
Symbols.java, SlotMachine.java, and Reel.java) and the images
directory into Eclipse, and test your code.
See the Project Submission page for detailed instructions on how to submit your project.
You may resubmit your files as often as you like, but only the last submittal will be graded and will be used to determine if your project is late. For more information, see the Projects page on the course web site.
Remember — if you make any change to your program, no matter how insignificant it may seem, you should recompile and retest your program before submitting it. Even the smallest typo can cause errors and a reduction in your grade.