Homework 5: Rock - Paper - Scissors Game
Objective: To play the rock-paper-scissors game
Write a program to ask a player to input either Rock,
Paper, or Scissors, playing against the computer, and then make one of the following happen:
- Rock breaks scissors
- Paper covers rock
- Scissors cut paper
- There is a tie (both players picked the same thing)
Here is some sample output showing how your program should work:
[cpersiko@localhost cs111a]$ java Lab2
Welcome to Craig's Rock-Paper-Scissors Game
Please enter your move: rock
Computer's move is Scissors
You Win! Rock Breaks Scissors!!
[cpersiko@localhost cs111a]$ java Lab2
Welcome to Craig's Rock-Paper-Scissors Game
Please enter your move: Rock
Computer's move is Paper
Computer Wins! Paper Covers Rock!!
[cpersiko@localhost cs111a]$ java Lab2
Welcome to Craig's Rock-Paper-Scissors Game
Please enter your move: Paper
Computer's move is Paper
Tie!!
[cpersiko@localhost cs111a]$ java Lab2
Welcome to Craig's Rock-Paper-Scissors Game
Please enter your move: paper
Computer's move is Scissors
Computer Wins! Scissors Cut Paper!!
[cpersiko@localhost cs111a]$ java Lab2
Welcome to Craig's Rock-Paper-Scissors Game
Please enter your move: Scissors
Computer's move is Paper
You Win! Scissors Cut Paper!!
[cpersiko@localhost cs111a]$ java Lab2
Welcome to Craig's Rock-Paper-Scissors Game
Please enter your move: scissors
Computer's move is Paper
You Win! Scissors Cut Paper!!
[cpersiko@localhost cs111a]$ java Lab2
Welcome to Craig's Rock-Paper-Scissors Game
Please enter your move: fish
Computer's move is Paper
Invalid move!!
[cpersiko@localhost cs111a]$
Here are the hints and rules:
- To generate a random number for the computer's move, you can use the
Math.random() method, which is described at the end of Chapter 4 of your textbook (see Notes on Random Number Generation for more info).
- Your program should be able to handle input starting with capital or lower-case letters (Both "Rock"
and "rock" mean "Rock"). You may look at just the first character of the input if you wish.
- You should use at least one switch statement or at least one multi-way if-statement (using "else
if").
- Your program should NOT say it's "Craig's Rock-Paper-Scissors Game" like mine does.
- When you turn in your program, show your program listing and sample output showing several different
situations to demonstrate the random behavior, and many possible combinations.
Return to CS 111A page