Question
Write a Java program that allows the user to play the game or Rock, Paper Scissors 5 times. Remember: Rock crushes scissors, Scissors cuts paper,
Write a Java program that allows the user to play the game or Rock, Paper Scissors 5 times.
Remember: Rock crushes scissors, Scissors cuts paper, Paper hides rock.
A sample template has been provided with pseudocode. If you know how to do this problem without using the template, please do so. Otherwise, copy the code into your editor and follow the instructions below:
- Name your program file: xxxx_C5Lab1.java, where xxxx is your kean email id.
- Please hand in hand in java file and screen print of output.
-The assignment will be completed in pairs.
- In a header (comment at top of program), include your name, the name of you and
your partner, the date and a description of the assignment. Each student must hand in their own copy.
The assignment is due before start of next class. We will go over the assignment at the start of the next. Once we go over the assignment, it can only be handed in for 12 credit before the following class.
Sample run:
Enter 1 for Rock, 2 for Paper, 3 for Scissors
1
Player picked Rock, Computer Paper. Computer wins Enter 1 for Rock, 2 for Paper, 3 for Scissors 2 Player picked paper, Computer Scissors. Computer wins Enter 1 for Rock, 2 for Paper, 3 for Scissors
3
Player picked Scissors, Computer Paper. Player wins Enter 1 for Rock, 2 for Paper, 3 for Scissors 1 Tie
Enter 1 for Rock, 2 for Paper, 3 for Scissors
2
Player picked paper, Computer Scissors. Computer wins
Computer wins: 3 Player wins: 1
The Following Code:
import java.util.Scanner;
public class RPS {
//This class allows a player to play RPS 5 times
public static void main(String[] args) {
Scanner reader = new Scanner (System.in);
//variables for player choice and computer choice
int player = 0, computer = 0;
//score variables
int computerScore = 0, playerScore =0;
//Add a loop to play the game of RPS 5 times.
//Pseudocode for 1 game of RPS
//Generate the computer's choice
//1 = rock
//2 = paper
//3 = scissors
computer = (int)(Math.random() * 3) + 1; //computer choice
System.out.println("Enter 1 for Rock, 2 for Paper, 3 for Scissors");
player = reader.nextInt();
//player choice
//Complete the code to determine who wins and add to computer or player score
//Rock crushes scissors, paper hides rock, scissors cuts paper
// if player is equal to computer => tie
// if player picks Rock then
// if computer choice is paper, computer wins
// if computer choice is scissors, player wins
// otherwise if player picks paper then
// if computer choice is rock,player wins
// if computer choice is scissors, computer wins
// otherwise if player picks scissors then
// if computer choice is rock, computer wins
// if computer choice is paper, player wins
// otherwise, the player picked an invalid choice. Do not count the game.
//End of loop here.
//print number of computer wins and player wins
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started