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.

  1. Using composition in an object-oriented design
  2. Interfacing with code designed and implemented by someone else
  3. Using enumeration
  4. Writing unit tests

To continue to gain experience in the following areas.

  1. Documenting classes
  2. 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.

  1. A "Bet One" button. This allows the user to bet a single credit.
  2. 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.
  3. A "Reset" button. This allows the user to return the amount that he/she has bet to the credits that he/she still has.
  4. A "Spin" button. This causes the three reels to spin.
  5. An information area. Information as to the status of the machine and the game just played are displayed in this area.
  6. 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.
  7. 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.
  8. 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.

  1. Game allows the user to add more credits to play with.
  2. 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.
  3. 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.

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

  1. The Javadoc for the SlotMachine, Reel and Symbol classes can be found here.
  2. The code for the Symbol class and the images 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 import Symbols and images into your project, do the following.
    1. Open Eclipse
    2. Select: File
    3. A pop-up window should appear. Click on Import ...
    4. Click on Existing Projects into Workspace, then click Next
    5. Another pop-up window will appear. Click the button for Select archive file:
    6. Click Browse and navigate to the Project2.zip file that you saved earlier
    7. Double-click on the Project2.zip file
    8. One last pop-up, Import Projects, will appear. Click Finish.
    A project named Project2 shoud appear in the list on the left-hand side of your screen. If you navigate down to src, you will see that the Symbol class and the images file are there. You are now ready to add your SlotMachine and Reel classes.
  3. 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.
  4. 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.
  5. 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?
  6. You must comment using Javadoc formatting for both function and class headers.
  7. All methods of the SlotMachine and Reel classes must have appropriate method header comments, including pre- and post-conditions, as shown in the course coding standards and discussed in class.
  8. 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!
  9. Both the SlotMachine and Reel classes should have file header comments, including class invariants.
  10. You must thoroughly unit test the isWinner method in the SlotMachine 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.