THINK FIRST·CODE LATER

← All labs

Rock, paper, scissors referee

Problem

Write RockPaperScissors: read the moves of player 1 and player 2 (rock, paper or scissors, in any letter case) and print the result:

  • Invalid move: lizard if a move is not one of the three (report player 1's move if both are invalid);
  • Draw: both chose paper;
  • otherwise Player 1 wins: rock beats scissors.

Use a switch on player 1's move to decide the winner, and boolean variables to make the conditions readable.

For the input

rock scissors

the program prints

Player 1 wins: rock beats scissors

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

l6-6-data-1.txt

rock scissors
What your program must print for l6-6-data-1.txt
Player 1 wins: rock beats scissors

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < l6-6-data-1.txt

Windows PowerShell does not understand <:

Get-Content l6-6-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.