Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* Hi! I am struggling with a program to play Rock Paper Scissors. I am confused about how to calculate wins, looses, and draws. My

/* Hi! I am struggling with a program to play Rock Paper Scissors. I am confused about how to calculate wins, looses, and draws. My TA said I need to use return in PlayOneRound method, but I still can't totally understand it and I am too guilty to bother her agian. Sorry for letting you face these ugly code.*/ /*btw. Our professor restricts us to only use one scanner, that is the keyboard. // CS312 Students. Do not change the following line. // This is what our professor gave us to let computer make predictable random choice RandomPlayer computerPlayer = buildRandomPlayer(args); // CS312 students do no change the following line. // Do not make any other Scanners. Scanner keyboard = new Scanner(System.in); */ /* And I forgot to say, I just wrote following things under the class public static final int playerWin = 0; public static final int computerWin = 0; public static final int numDraws = 0; */ //Play one round public static int oneRound(Scanner keyboard, RandomPlayer computerPlayer){ System.out.println(playerName(keyboard) + ", please enter your choice for this round."); playerChoice(keyboard); int playerChoice = playerChoice(keyboard); int computerChoice = computerPlayer.getComputerChoice(); System.out.println("Computer picked " + computerChoice + ", " + playerName(keyboard) + "picked" + playerChoice(keyboard)); System.out.println(); if(computerChoice == ROCK && playerChoice == PAPER){ System.out.println("PAPER covers ROCK. You win."); return playerWin; } else if (computerChoice == ROCK && playerChoice == SCISSORS) { System.out.println("ROCK breaks SCISSORS. I win."); return computerWin; } else if (computerChoice == PAPER && playerChoice == ROCK) { System.out.println("PAPER covers ROCK. I win."); return computerWin; } else if (computerChoice == PAPER && playerChoice == SCISSORS) { System.out.println("SCISSORS cut PAPER. You win."); return playerWin; } else if (computerChoice == SCISSORS && playerChoice == ROCK) { System.out.println("ROCK breaks SCISSORS. You win."); return playerWin; } else if (computerChoice == SCISSORS && playerChoice == PAPER) { System.out.println("SCISSORS cut PAPER. I win."); return computerWin; } else{ System.out.println("We picked the same thing! This round is a draw."); return numDraws; } } //Play rounds public static void playRounds(Scanner keyboard, RandomPlayer computerPlayer){ for (int i =1; i < roundNumber(keyboard); i++){ System.out.println("Round" + i + "."); oneRound(keyboard, computerPlayer); } }

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

Recommended Textbook for

A Concise Introduction to Logic

Authors: Patrick J. Hurley, Lori Watson

13th edition

1305958098, 978-1305958098

More Books

Students also viewed these Programming questions