Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program for a Rock-paper-scissors program code with the following rules: The rules of the game are as follows: Each player chooses Rock,

Write a Java program for a Rock-paper-scissors program code with the following rules:

The rules of the game are as follows:

  1. Each player chooses Rock, Paper, or Scissors.
  2. If both players (user vs. computer) choose the same thing, the round is a tie.
  3. Otherwise:
    1. Paper wraps Rock to win
    2. Scissors cut Paper to win
    3. Rock breaks Scissors to win
  • The program first asks the user how many rounds he/she wants to play.
    • Maximum number of rounds = 10, minimum number of rounds = 1. If the user asks for something outside this range, the program prints an error message and quits.
    • If the number of rounds is in range, the program plays that number of rounds. Each round is played according to the requirements below.
  • For each round of Rock, Paper, Scissors, the program does the following:
    • The computer asks the user for his/her choice (Rock, Paper, or Scissors).
      • Hint: 1 = Rock, 2 = Paper, 3 = Scissors
    • After the computer asks for the users input, the computer randomly chooses Rock, Paper, or Scissors and displays the result of the round (tie, user win, or computer win).
      • Hint: use the Random class.
  • The program must keep track of how many rounds are ties, user wins, or computer wins.
    • Hint: Create three variables to keep track of these items and update them correctly after each round.
  • The program must print out the number of ties, user wins, and computer wins and declare the overall winner based on who won more rounds.
  • After all rounds have been played and the winner declared, the program must ask the user if he/she wants to play again.
    • If the user says No, the program prints out a message saying, Thanks for playing! and then exits.
    • If the user says Yes, the program starts over, asking the user how many rounds he/she would like to play.

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

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

10-2 What are the principal e-commerce business and revenue models?

Answered: 1 week ago