Write a program that allows the user to play Rock, Paper, Scissors. Write the RPS class....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a program that allows the user to play "Rock, Paper, Scissors". Write the RPS class. All code should be in one file. main() will be part of the RPS class, fairly small, and contain only a loop that asks the user if they want to play "Rock, Paper, Scissors". If they say yes, it calls the static method play() of the RPS class. If not, the program ends. play() has no parameters, and no return value. (In this exercise, the class RPS does contain code that will input and output to the user.) Use GUI for all input and output. Note that since play() is a static method, it can be called directly on the RPS class - main() should not instantiate an RPS object. play() will allow one full game of RPS to run. To win an RPS game, the player or the computer must win 2 out of 3 rounds. The following should all be done inside the RPS class: • Decide how the user will input rock, paper or scissors: character? string? integer? Prompt the user to input rock, paper, or scissors. Use simple constants (static final) to represent ROCK, PAPER, and SCISSORS. • Use enums to represent WIN, LOSE, TIE. (This is the result of each round.) Use the Random class to generate random computer choices. (Don't use Math.random). • For each round, print out what the player threw, what the computer threw, and who won or if there was a tie. In RPS, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. Optimize your code so that you are testing as few cases as possible, but covering all the possible combinations. Keep track of the number of rounds that the player has won and the computer has won. • When someone wins the game (wins 2 rounds), print out a message indicating whether the player or the computer has won, and return to main(). Write a program that allows the user to play "Rock, Paper, Scissors". Write the RPS class. All code should be in one file. main() will be part of the RPS class, fairly small, and contain only a loop that asks the user if they want to play "Rock, Paper, Scissors". If they say yes, it calls the static method play() of the RPS class. If not, the program ends. play() has no parameters, and no return value. (In this exercise, the class RPS does contain code that will input and output to the user.) Use GUI for all input and output. Note that since play() is a static method, it can be called directly on the RPS class - main() should not instantiate an RPS object. play() will allow one full game of RPS to run. To win an RPS game, the player or the computer must win 2 out of 3 rounds. The following should all be done inside the RPS class: • Decide how the user will input rock, paper or scissors: character? string? integer? Prompt the user to input rock, paper, or scissors. Use simple constants (static final) to represent ROCK, PAPER, and SCISSORS. • Use enums to represent WIN, LOSE, TIE. (This is the result of each round.) Use the Random class to generate random computer choices. (Don't use Math.random). • For each round, print out what the player threw, what the computer threw, and who won or if there was a tie. In RPS, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. Optimize your code so that you are testing as few cases as possible, but covering all the possible combinations. Keep track of the number of rounds that the player has won and the computer has won. • When someone wins the game (wins 2 rounds), print out a message indicating whether the player or the computer has won, and return to main().
Expert Answer:
Answer rating: 100% (QA)
The java code is as follows import javautil enum State WIN LOSE TIE class RPS Constants to represent ... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
Write a program that allows the user to enter his or her name. The program should output a username for entry into a website. The user should be prompted to enter a first name, middle initial, and...
-
Write a program that allows the user to enter time in seconds in the text field and press the Enter key to count down the seconds, as shown in Figure 16.45d. The remaining seconds are redisplayed...
-
Write a Python program that allows the user to enter a four-digit binary number and displays its value in base 10. Each binary digit should be entered one per line, starting with the leftmost digit...
-
Explain why a safety net can save the life of a circus performer.
-
Consider the example in Table 4.6. Suppose that losses are fully tax-deductible. What is the expected after-tax profit in this case? XYZ mines copper, with fixed costs of $0.50/lb and variable cost...
-
Creative Hearing Technologies of London recently introduced a Bluetooth enabled hearing aid that allows hearing-disabled users to not only hear better, but also interface with their cell phones and...
-
Professional pricing is used by people who have great skill in a particular field, such as doctors, lawyers, and business consultants. Find examples (advertisements, personal contacts) that reflect a...
-
Shawn Bishop, a neuroscience PhD student at Clarksville University, has been having problems balancing his checkbook. His monthly income is derived from a graduate research assistant ship; however,...
-
According to a magazine, 55% of all federal inmates are serving time for drug dealing. A random sample of 15 federal inmates is selected. USE SALT (a) What is the probability that 11 or more are...
-
After its first month of operations, Paquette Advisors showed the following account balances in its general ledger accounts (T-accounts) as at January 31, 2020. During February, the following...
-
Derived from the tight-binding Hamiltonian of graphene, the band structure of graphene is composed by two branches: Yo f(kr, ky)| 1 - sof(kx, ky)| and -Yo f(kx, ky)| 1 + $0 |f (kx, ky)' where so...
-
If you were the editor of a newspaper would you have published pictures of "the falling man" picture the day after September 11 and that of the woman feeding a dog on a bridge with a dead body...
-
DB Company issued $ 2 0 0 , 0 0 0 , 0 0 0 of 8 % 2 0 - year bonds at 1 0 1 on 1 / 1 / 2 3 to yield 7 . 5 % . Interest is paid on June 3 0 and December 3 1 . Using effective - interest amortization,...
-
In Ontario, British Columbia, Manitoba, New Brunswick, Nova Scotia, Prince Edward Island, and the federal jurisdiction, labour relations boards have the authority to certify a union as the bargaining...
-
A worker pushes a heavy box with a force of 250 N at an angle = 38 below horizontal as shown. The box slides on level ground over a distance of 50 m. A friction force of 160 N acts on the box during...
-
Discuss the scope and objectives of internal audits, and how they assist management in identifying operational inefficiencies, detecting fraud, and enhancing overall governance processes. Provide...
-
Question 6 of 19 Crystal invested 45% of his money in mutual funds, 30% in real estate, and 25% in stocks. If the value of the money that he invested in mutual funds, real estate, and stocks grew by...
-
At the beginning of its fiscal year, Lakeside Inc. leased office space to LTT Corporation under a seven-year operating lease agreement. The contract calls for quarterly rent payments of $25,000 each....
-
Write a program that enables the user to add and remove points in a two-dimensional plane dynamically, as shown in Figure 15.29a. A minimum bounding rectangle is updated as the points are added and...
-
Find the first ten square numbers that are greater than Long.MAX_VALUE. A square number is a number in the form of n2. For example, 4, 9, and 16 are square numbers. Find an efficient approach to run...
-
Write a program that enables the user to specify the location and size of the circles and displays whether the two circles intersect, as shown in Figure 16.39a. Enable the user to point the mouse...
-
Time value is the anticipation of intrinsic value being stronger than it is now. However, intrinsic value can drop. Why then can time value not be negative?
-
In concrete terms, what does the difficulty in valuing an option boil down to?
-
Show how the purchase of an option and the sale of another option can protect you against the risk of a drop in the value of the underlying share, without costing you anything if you give up the...
Study smarter with the SolutionInn App