Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

DRAW A COMPLETE FLOWCHART FOR THE FOLLOWING CODE : import java.util.Scanner; import java.util.Random; public class RPSLS { public static int menu() { Scanner scan =

DRAW A COMPLETE FLOWCHART FOR THE FOLLOWING CODE :

import java.util.Scanner; import java.util.Random;

public class RPSLS {

public static int menu() { Scanner scan = new Scanner(System.in); System.out.println(" Menu:"); System.out.print(" 1. Play Game 2. Show Score 3. Quit "); int input = scan.nextInt();

return input; }

public static void winner(char player, int computer) { if(player == 'R' && computer == 2) System.out.println("Paper covers Rock"); else if(player == 'R' && computer == 3) System.out.println("Rock crushes Scissors"); else if(player == 'R' && computer == 4) System.out.println("Rock crushes Lizards"); else if(player == 'R' && computer == 5) System.out.println("Spock vaporizes Rock"); else if(player == 'P' && computer == 1) System.out.println("Papers covers rock"); else if(player == 'P' && computer == 3) System.out.println("Scissors cuts Paper"); else if(player == 'P' && computer == 4) System.out.println("Lizard eats Paper"); else if(player == 'P' && computer == 5) System.out.println("Paper disproves Spock"); else if(player == 'S' && computer == 1) System.out.println("Rock crushes Scissors"); else if(player == 'S' && computer == 2) System.out.println("Scissors cuts Paper"); else if(player == 'S' && computer == 4) System.out.println("Scissors decapitates Lizard"); else if(player == 'S' && computer == 5) System.out.println("Spock smashes Scissors"); else if(player == 'L' && computer == 1) System.out.println("Rock crushes Lizards"); else if(player == 'L' && computer == 2) System.out.println("Lizard eats Paper"); else if(player == 'L' && computer == 3) System.out.println("Scissors decapitates Lizard"); else if(player == 'L' && computer == 5) System.out.println("Lizard poisons Spock"); else if(player == 'K' && computer == 1) System.out.println("Spock vaporizes Rock"); else if(player == 'K' && computer == 2) System.out.println("Papers disproves Spock"); else if(player == 'K' && computer == 3) System.out.println("Spock smashes Scissors"); else if(player == 'K' && computer == 4) System.out.println("Lizard poisons Spock");

}

public static void main(String[] args) { Scanner scan = new Scanner(System.in); char player; int playerWin = 0, computerWin = 0; Random rand = new Random(); while(true) { int input = menu(); if(input == 1) { int computer = rand.nextInt(5)+1; System.out.println("Choose your weapon"); System.out.println(" R. Rock P. Paper S. Scissors L. Lizzard K. Spock"); player = scan.next().charAt(0); System.out.print("You choose ");

switch(player) { case 'R': System.out.print("Rock"); break; case 'P': System.out.print("Paper"); break; case 'S': System.out.print("Scissors"); break; case 'L': System.out.print("Lizard"); break; case 'K': System.out.print("Spock"); break; }

System.out.print(" "); System.out.print("Computer chose "); switch(computer) { case 1: System.out.print("Rock"); break; case 2: System.out.print("Paper"); break; case 3: System.out.print("Scissors"); break; case 4: System.out.print("Lizard"); break; case 5: System.out.print("Spock"); break; } System.out.print(" ");

// calculating the player wins if(player == 'K' && computer == 3 || player == 'S' && computer == 2 || player == 'P' && computer == 1 || player == 'R' && computer == 4 || player == 'L' && computer == 5 || player == 'P' && computer == 4 || player == 'P' && computer == 5 || player == 'R' && computer == 3 || player == 'S' && computer == 1 || player == 'L' && computer == 2) { winner(player,computer); playerWin++; } // calculating the computer wins else if(player == 'R' && computer == 2 || player == 'R' && computer == 5 || player == 'P' && computer == 3 || player == 'S' && computer == 1 || player == 'S' && computer == 4 || player == 'S' && computer == 5 || player == 'L' && computer == 1 || player == 'L' && computer == 3 || player == 'S' && computer == 2 || player == 'S' && computer == 4) { winner(player,computer); computerWin++; } // calculating the ties if(player == 'R' && computer == 1 || player == 'P' && computer == 2 || player == 'S' && computer == 3 || player == 'L' && computer == 4 || player == 'K' && computer == 5) { System.out.println("Tie "); } }

if(input == 2) { System.out.println("Player = " + playerWin); System.out.println("Computer = " + computerWin); System.out.println(" "); } if(input == 3) break; } // showing the score System.out.println(""); System.out.println(" Final Score"); System.out.println("Player = " + playerWin); System.out.println("Computer = " + computerWin); } }

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

=+ What are the information and consultation requirements?

Answered: 1 week ago

Question

=+ Should the MNE belong (why, why not)?

Answered: 1 week ago