Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I can't figure out why this is not working! import java.util.Scanner; public class RockPaperScissors { public static void main(String[] args) { // TODO Auto-generated method

I can't figure out why this is not working!

import java.util.Scanner;

public class RockPaperScissors {

public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); int rounds, cscore=0, uscore=0, counter = 0; System.out.println("Lets play Rock, Paper, Scissors!" + " How many rounds would you like to play?"); System.out.print("Points to win: "); rounds = input.nextInt(); while(counter==0) { System.out.println("Rock, paper, or scissors?"); String playerMove = input.next(); String computerMove = ComputerOpponent.getMove();

if (playerMove == computerMove) { System.out.println("IT'S A TIE"); } else if(playerMove == "rock") { if(computerMove == "paper") { System.out.println("The computer chose paper, so you lose."); cscore++; System.out.print(uscore + "-" + cscore); }else if(computerMove == "scissors") { System.out.println("The computer chose scissors, so you win!"); uscore++; System.out.print(uscore + "-" + cscore); } } else if(playerMove == "paper") { if(computerMove == "rock") { System.out.println("The computer chose rock, so you win!"); uscore++; System.out.print(uscore + "-" + cscore); }else if(computerMove == "scissors") { System.out.println("The computer chose scissors, so you lose."); cscore++; System.out.print(uscore + "-" + cscore); } } else if(playerMove =="scissors") { if(computerMove == "rock") { System.out.println("Computer chose rock, so you lose."); cscore++; System.out.println(uscore + "-" + cscore); }else if(computerMove == "paper") { System.out.println("Computer chose paper, so you win!"); uscore++; System.out.println(uscore + "-" + cscore); } if(uscore == rounds) { System.out.println("Congratulations! You won!"); } else if(cscore == rounds) { System.out.println("Sorry, you lost. Better luck next time!"); } } } }}

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Creating A Database In Filemaker Pro Visual QuickProject Guide

Authors: Steven A. Schwartz

1st Edition

0321321219, 978-0321321213

More Books

Students also viewed these Databases questions