CPE 101:
Fundamentals of Computer Science 1
Spring 2003
(Sections 02 & 03 only) |
Program # 3
Due by 9 pm, Sunday, of Week # 5. |
Task Navigation Links:
|
The Basic Task |
|
Program 1: The Minimum Required |
Program 2: Aiming Higher ... |
|
Some Reminders |
Submitting Your Work |
The Basic Task
For your third programming assignment, you will implement a couple of variations on a "slot machine" simulation.
Part 1: the minimum required.
- Your first program, a Java application program, must be called:
SlotGame.java
- In some ways, it will be quite similar to TwoDice. (You may adapt that, or start over: whichever you choose, make sure to document that under your program History.) The main differences, at this point, are that:
- instead of reporting the simulation of a die rolling, which results in a face number, you will report the simulation of a wheel spinning, which will result in a color; and
- rather than reporting a sum of the numerical faces of two dice, you will report how many of the slots show the same face color.
- Your simulation will generate a random integer from 1 to 8 for each slot. Your program will contain code to map those numbers as follows:
If the random number is: |
Report the color as: |
If the random number is: |
Report the color as: |
1 |
red |
5 |
blue |
2 |
orange |
6 |
magenta |
3 |
yellow |
7 |
pink |
4 |
green |
8 |
cyan |
0 |
black |
Include "black" for special cases, such as:
a slot that is not visible, or
a slot machine that's not turned on.
|
- Your slot machine will contain three (3) slots. The first and third will use all eight (8) options, while the second (middle) slot will use only the five basic spectrum-colors (red, orange, yellow, green, or blue, numbers 1 through 5). But use variables, as needed, so that it will be relatively simple in future assignments to use different numbers for both the number of slots and the number of faces per slot.
- It will report the spin results and the player's winning (or not) according to these rules:
- If all three slots match, it will report a win.
- If any two slots match, it will report a draw.
- If no slots match, it will report a loss.
- You may use your own choice as to the exact words you display to the player, as long as your program follows the logic described above. Some sample runs of the program might look like this (where the computer's displays are shown in black and the player's in green):
% java SlotGame
Welcome to the 101 Casino!
Spinning ... pink blue orange
Sorry! You lose ...
|
% java SlotGame
Welcome to the 101 Casino!
Spinning ... green green green
Wow! All three match!
|
% java SlotGame
Welcome to the 101 Casino!
Spinning ... yellow red magenta
Sorry! You lose ..
|
% java SlotGame
Welcome to the 101 Casino!
Spinning ... cyan yellow cyan
Two match! You break even on this round.
|
- When you are finished with this assignment, use handin to submit your program,
SlotGame.java
, to the Pgm3 folder for your section.
Program 2: Do this part too, to be eligible for a higher grade.
For this part, you will write an applet that must be named
SlotApplet.java
and be called by a web page that must be named
SlotApplet.html.
It is to do the following:
- Determine three (3) colors, randomly, from the set of eight (8) possible ones given above. Continue to use variables rather than hard-coding numbers throughout your program, since the number of options will vary in later assignments.
- Display, next to each other on the screen, three squares, one of each color that was randomly generated.
- Print an appropriate statement under the squares, such as:
- All three match: Jackpot!
- Two match: Even return!
- None match: Sorry...
- Get that much to run. Make sure it comes up something like one student's submission, it works roughly like
this. Make sure yours works better, and works with both the appletviewer and a web browser.
In addition to the specific rules of the slot machine operation described above, here are a few additional conditions on your assignment:
- In your .html file, indicate that the applet should display with a width of 600 and height of 400.
- Make sure your slot machine graphics, plus the notice about how much if anything the person won, will fit into that space.
- Don't make that too tight a fit either. Remember that, later on, you may want extra space for a welcome, entering the player's name and / or a bet, asking if the person wants to play again, displaying additional slots, etc. Plan ahead for such reasonable extensions.
Notice that this applet requires you to isolate the part of your previous work that generates and displays the results of a game, and convert that to an applet. Nonetheless, large portions of your code from the program in part 1 should be re-usable, or easily modified, for this program. You should make sure that your code is now as accurate, efficient, and well-documented as you can make it. While you're at it, do any additional clean-up that may be needed, including but not limited to:
- Simplify the design and subsequent coding as much as possible. For example, are your conditional statements structured as well as they might be? How do any loops improve the program structure? Are you going through a lot of intermediate steps that could be consolidated; conversely, are you taking unnecessary shortcuts that will not be easy to modify when the program requirements change?
- Your main (paint) method should be relatively brief. Isolate various supporting actions, whether graphical or mathematical, into separate methods. (And make sure they are documented appropriately.) Make sure you understand how the use (or not) of objects affects whether (or not) you need to declare things (e.g., methods) to be static.
Some Reminders
There are several things you can do to prepare for the applet part of this assignment:
- Review your textbook, and make sure you have a thorough design document for your previous programming assignments. If you find them lacking, clean them up before you proceed.
- Review your textbook and your lecture notes on writing methods, and reconsider any previous design decisions you made in writing your previous programs. Create alternative designs, as needed.
- Review the textbook on drawing via applets, and experiment with some of code for the applets from the textbook before plunging into writing your own. (Notice, for example, the extra commands in the class declaration, the use of a paint() method instead of a main() method, the way the Graphics object "page" is referenced with respect to the various Graphics methods, the way the coordinate system is laid out, etc.)
Needless to say, your grade (on both parts) will depend on whether your code works as specified, and whether it meets the various standards from previous assignments, class discussions, textbook guidelines, and course expectations. Thus, for example, you are expected to include appropriate documentation, follow standard naming conventions, use indentation and whitespace, develop a neat and efficient design, and implement it cleanly. You are expected to demonstrate capability with the various tools we have covered so far in class, including but not limited to the appropriate use of selection and loop structures, primitive data types, objects, and methods. If you can't get something to work as requested (even after using the various sources of help available to you), document what you have tried and what you know about why it has failed. You won't get full marks for that, but you will lose fewer points than you would if you submit a program with any fairly obvious problem(s) to which you appeared to be oblivious.
Submitting Your Work
Use the "handin" facility available from your Central Unix account on Polylog1 to submit these required files:
- SlotGame.java
(your source code for Part 1)
- SlotApplet.java
(your source code for Part 2)
- SlotApplet.html
(the page that calls your code for Part 2)
It is expected that your source code will contain full internal documentation. Use the standard comment block at the beginning of the program for your design specifications and other general information. Use comments throughout your programs to clarify to anyone reading your program what you are doing at each step along the way. If you have additional comments to make, you may submit a supplemental README document, in plain text format, but its existence must be documented in the program file you submit.
Remember, the use of "handin" is described in a separate
information sheet, supplemented by a
FAQ. There also exists a page of general
guidelines for completing your programming assignments (which documents the one unwavering rule: to receive any credit at all for the assignment, your program must compile in our lab environment!)
Copyright © 2000.
by Carol Scheftic.
All rights reserved. Used by permission.
Requests to reuse information from this page should be directed to Carol Scheftic.
Page created 1 April 2001;
last updated
10 July 2001.