Objectives
To gain experience
- using Scanner( ) object for console input
- using System.out for console output
- writing methods in Java
- using objects/classes written by other programmers
Description
The game of Rock, Paper, Scissors is very popular among children
and adults alike. Rock, Paper, Scissors (RPS for short) is a two player game in which each
the players simultaneously extend their right hand in one of three gestures. The shape of a fist represents
a Rock, an open flat hand with the palm down represents Paper, and having the index and middle finger spread apart represents a pair of Scissors. RPS is often used as a selection technique much like flipping a coin is used.
The winner is decided by these rules
- If both players gesture in the same manner the game is tied.
- Rock smashes Scissors; Rock wins
- Paper smothers Rock; Paper wins
- Scissors cut Paper; Scissors win
Strategies abound for those who take the game seriously. Check the web sites for the
World RPS Society and the
USA Rock Paper Scissors League.
See
the RPS Wikopedia entry for
much more information.
Your assignment is to implement the game of RPS in which your program plays a series of RPS games
against your program's user; decides who wins each game (or if there is a tie) in the series; then prints a summary of the outcomes for the series;
Project Policy
This project is considered an
OPEN project. This means
- You should try as much as possible to complete the project by yourself.
- You may get assistance from anyone -- TAs, instructors, fellow students, relatives, friends, etc.
- You must document all outside help you get as part of your file header comment.
This
DOES NOT mean
- that you may copy anyone else's code
- have someone else write your code for you
- submit someone else's code as your own
Such offenses are violations of the student code of academic conduct.
Project Requirements
- All code should be in a single file which MUST be named Project1.java which has a single public class also named Project1.
- You must declare your class to be part of the package named proj1.
To make your file part of the proj1 package, your .java file must include the statement
package proj1; as the first line of code.
Don't worry... we'll discuss packages soon
- Your program must provide this basic functionality which should be implemented in
main
- Prompt the user for the number of games (an integer) he wishes to play in the series
- For each game of RPS your program will choose Rock, Paper, or Scissors by using a random number generator
(RNG); prompt the user for his RPS choice; output the choices of both players and declare the winner
(or that the game was tied)
- When all games have been played, output a summary (the number of wins by each player and the number
of ties) of the series of RPS games.
- Your program must validate all user input and re prompt the user if the input is invalid.
- Your program must accept the user's RPS choice as a string with any combination of upper- and lower-case characters.
- Your program must produce all output listed below in any reasonable, readable format.
- Your code must make appropriate use of functions (in keeping with good top-down design) and constants (to avoid magic numbers). Define functions and constants
used by main within the Project1 class.
See the Project Hints below regarding how to define these methods and constants.
Project Hints
- Be sure to make good use of the String class.
- Your program will be tested with a variety of good and BAD inputs.
Get your project working with good input first. Then go back and put in the error checking and error handling.
- To generate random numbers for your programs choice, you will create a random number generator object
with the statement
Random rng = new Random( ).
You can obtain a random integer in the range 0 to N-1 with the statement
int x = rng.nextInt( N );
- To have access to the class definition for Random, your code must include
the statement
import java.util.Random;
- Use the Scanner class in main for user input.
To have access to the class definition for Scanner, your code must include
the statement
import java.util.Scanner;
- Since main is (by definition) a static method,
all methods and constants that are also defined within the
Project1 class and used by main must also be defined as
static. Constants and variables defined within main
are of course local variables, so this requirement does not apply to them.
- To create a constant (like a #define in C), use the final modifier
in addition to any other modifiers necessary.
- Arrays are not required (we haven't covered them yet), but if you're familiar with Java you may
use arrays if you like.
Your program must output the results for each "game" and cumulative statistics for the complete "series" of games.
For each game, your program must output
- Your program's choice of Rock, Paper, or Scissors
- The user's choice of Rock, Paper, or Scissors
- The result of the game
When all games in the series have been played, your program must output
- The number of games in the series
- The number games your program won
- The number of games the user won
- The number of games that were tied
Project Questions
In lieu of a project design assignment, you will be answering a few questions about your
code to evaluate your understanding of objects and methods. Copy the file
p1questions.txt from Mr. Frey's public directory
/afs/umbc.edu/users/f/r/frey/pub/CMSC202/Proj1
then edit the file as indicated. Submit this file as part of your project along with your project code.
Grading
The grade for this project will be broken down as follows. A more detailed
breakdown will be provided in the grade form you receive
with your project grade.
10% - Project Questions
Be sure to submit your project questions file by the project due date.
80% - Correctness
This list may not be comprehensive, but everything on this list will be
verified by the graders.
- Your project produces all required output.
- The output produced is correct.
- The output is in a reasonable, readable format.
- Constants are used wherever appropriate.
- All project requirements are met.
10% - Coding Standards
Your code adheres to the
CMSC 202 coding standards as discussed and reviewed in class.
In particular, since this is your first CMSC 202 program, pay particular attention to
the list below. Graders will check all applicable items in the coding standards.
- Your file header comments
- Your method header comments (particularly pre- and post-conditions)
- Method and variable names
- Code readability
- Limiting variable scope
Project Submission
Steps for Submission
- submit all files
- submitls to verify they are in the remote directory
Assuming you've used the recommended file names, then
to submit your project, type the command
submit cs202 Proj1 Project1.java p1questions.txt
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.
You can check to see what files you have submitted by typing
submitls cs202 Proj1
More complete documentation for submit and related commands can be found
here.
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.