Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am struggling on this assignment. I can't figure out how to get the game to tie and not give points to either side. Assignment

I am struggling on this assignment. I can't figure out how to get the game to tie and not give points to either side.

image text in transcribedimage text in transcribedimage text in transcribed

Assignment In this lab, you will implement a version of Rock, Paper, Scissors where the user plays against the computer. The user puts in their choice as a String (either "rock", "paper" or "scissors"- not case sensitive), and the computer will make its choice at random. The winner should be determined based on the rules above The user should be able to play multiple rounds of Rock, Paper, Scissors against the computer The program keep track of the score of both the computer and the user. If there is a tie, neither player gets a point. The program should keep running until cither the player or the computer wins the number of games they specified at the start. So, for example, if the user inputs 3 when prompted, the game should continue until either the user or the computer wins three rounds (not once three rounds have been played). should first ask the user how many wins they want to play. Your program should After each tum, the program should print who won (either the player or the computer) and the score after that turn. Show the player's score first (for example, if the computer has won once and the player has not won, show (01. More examples of this can be seen in the sample runs below Instructions Star by creating a new class named RockPaperscissors. Download the file Computeropponent.java from the CSCI 1301 site.I contains the code that generates the computer's move for you. Once you have downloaded it, move the file into the sre folder of your RockPaperScisors project. should be located directly alongside your RockPaperScissors.java file in the same sre folder Once you have both files in Eclipse, feel free to explore ComputerOpponent.java. Theres nothing in the code beyond anything we've covered already. Notice the variable, static boolean TESTING MODE false; When TESTING-MODE 1s false, computeropponent. java will generate computer moves randomly using Math.random ). However, if you change TESTING MODE to true, the moves that the computer generates will always come in a fixed order: rock, paper, scissors, rock, paper, scissors, rock, paper, scissors,... and so on. You may find it useful to change TESTING MODE to true when you predicted. This will also help our TA's when they are grading your code are testing and debugging your program, since the computer's moves can be We will use our own version of ComputerOpponent.java when grading your lab, so don't worry about messing with the functionality of that file (but make sure that all of the code yoru write stays in RockPaperScissors.java). Do not rename ComputerOpponent.java, as doing so will cause a compilation error when we try to grade your lab Once both java files are in the same src folder, you can get the ComputerOpponent.java by using its getMove) method. This method will retum a String value which wll be either "rock". "paper" or "scissors" (each being all lowercase). Here is the line of code to get the computer's move: computer move from String computerMoveComputeropponent.getMove) On each turn, you should prompt the user for their move and retrieve it via the nextLine ( method. The game should be able to recognize rock". "paper", and "scissors" regardless of capitalization. If the user types something else, ask them to try again. Do not update either player's score if the user did not enter a valid move * This class gives you the computer's move in Rock, Paper, Scissors. public class ComputerOpponent private static boolean TESTING_MODEfalse; private static int cycler0 public static String getMove) t if (TESTING_MODE) switch (Cycler++ % 3) { case 0: case 1: default: I/ (case 2) return "rock"; return "paper" return "scissors"; else f switch ((int) (Math.random) 3)) case 0: case 1: default: // (case 2) return "rock"; return "paper"; return "scissors

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions