Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java please Objectives Use the static methods and static fields. Use the method-call/return mechanism. Use the random-number generation. Overload methods. Problem Specification Write a program

java please

Objectives

  • Use the static methods and static fields.
  • Use the method-call/return mechanism.
  • Use the random-number generation.
  • Overload methods.

Problem Specification

Write a program that lets a user play "Rock, Paper, Scissors" against the computer or computer against computer.

In user-computer game, the program should ask the user to choose one of the three choices, and then the computer randomly picks one (without knowing what the user has chosen). For this problem, the user should be asked to enter an integer: 1 for rock, 2 for paper, 3 for scissors. Rock beats scissors, scissors beats paper, paper beats rock. The program should say who wins, and then keep playing until someone (the user or the computer) has won 5 rounds. The computer needs to keep track of the current score and should also display it before each round.

In computer-computer game, play for 100 rounds and display which object won majority of the times.

Design Specification

  • Create Java class RPS.
  • Create static variables for storing Score1 and Score2.
  • Create a static method getRandom to get random integer between 1 and 3.
  • Overload play method like in the below screenshot.
  • Play() is for computer vs computer, play(userchoice) is for user vs computer.

image text in transcribed

Example:

Your program should work for both modes.

Mode 1:image text in transcribedmode 2image text in transcribed

1 package com.tamu.csci428; 3 import java.util.Random; 4 import java.util.Scanner; 6 public class RPS { static int score1 = 0; static int score2 = 0; static int getRandom() { void play() {0 void play(int userChoice) {. int whoWon(int choicei, int choice2) {O 54+ 93 94+ 1241 125 } public static void main(String[] args) {O 126 Select Mode : Enter 1 for Computer vs Computer, Enter 2 for User vs Computer Computer1 Score 31 Computer2 Score 40 Computer 2 won Select Mode : Enter 1 for Computer vs Computer, Enter 2 for User vs Computer Select 1. Rock 2.Paper 3. Scissors User won! Your choice 1 Computer choice 3 Your score : 1 Computer score : 0 Select 1. Rock 2.Paper 3. Scissors ITS A TIE! Your choice 2 Computer choice 2 Your score : 1 Computer score : 0 Select 1. Rock 2.Paper 3. Scissors User won! Your choice 3 Computer choice 2 Your score : 2 Computer score : 0 Select 1. Rock 2.Paper 3. Scissors ITS A TIE! Your choice 1 Computer choice 1 Your score : 2 Computer score : 0 Select 1. Rock 2.Paper 3. Scissors User won! Your choice 2 Computer choice 1 Your score : 3 Computer score : 0 Total number of games = 5 You won

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

More Books

Students also viewed these Databases questions

Question

Evaluate three pros and three cons of e-prescribing

Answered: 1 week ago