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.
-
Fourteen of the 16 infants in the Yale study elected to play with a toy resembling the helpful figure as opposed to one resembling the hindering figure. Is this convincing evidence that infants tend...
-
Think about how your organization (or one with which you are familiar) manages the performance of employees. Would you describe these practices as commitment- or control-oriented?
-
Write the following numbers in scientific notation form: 1. 428.9 2. -0.00000981 3. 8
-
The Walton Toy Company manufactures a line of dolls and a doll dress sewing kit. Demand for the dolls is increasing, and management requests assistance from you in determining an economical sales and...
-
A call option on a non-dividend-paying stock has a strike price of $60 and a time to maturity of six months. The risk-free rate is 4% and the volatility is 25%. The stock price is $56. What is the ...
-
What is the total number of missing checks in the sequence listed in the Cash Disbursements database? (Please select the choice that represents all possible correct answers.) b. How many duplicate...
-
Consider the following three cash flow series: End of YearCash Flow Series A Cash Flow Series B Cash Flow Series C 0 1 2 IN 34 5 -$1,000 X 1.5X 2.0X 2.5X 3.0X -$2,580 $2,870 $2,470 $2,070$1,670 $1, 1...
-
Silver Airlines, a privately held firm, is looking to perform a Initial Public Offering (IPO). They have hired you to value the firm using discounted cash flows. Since Silver is not traded in the...
-
If the sides of a triangle are 24 cm, 25 cm and 7 cm, then find the area of the triangle using Heron's formula
-
Objective 3.9 - Doubling Time and Half-Life The hourly wage of some Toyota automobile assembly line workers is being increased annually by the same percentage If their wage went from $6.90 to $12.01...
-
What evidence suggests that the warring entities are interested or even open to a diplomatic solution in the DRC? (please cite references) What are the feature of the UK political system?
-
How do cathodic protection (CP) systems work in mitigating corrosion in underground pipelines and marine structures, and what are the key considerations in designing and maintaining effective CP...
-
A company sells phones. The cost to manufacture x phones is C(x)= -25x^2 + 60000x + 18914 dollars. This includes overhead costs andproduction costs for each phone. If the company sells x phones for 2...
-
In the synthesis of the keto acid just given, the dicarboxylic acid decarboxylates in a specific way; it gives Explain. HO rather than HO
-
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...
-
5. YOU BE THE JUDGE WRITING PROBLEM Dominion Bank owned a large office building in Washington, D.C. Because it planned to sell the building, the bank stopped leasing new space and five of the 13...
-
7. ETHICS Jane says to Cody, "If you will agree to work as my yard man, I'll pay you $1,000 per week for a normal work week. You can start on Monday, and I'll guarantee you eight months' work." Cody...
-
8. Ronald Armstead worked for First American Bank as a courier. His duties included making deliveries between the bank's branches in Washington, D.C. Armstead parked the bank's station wagon near the...
Study smarter with the SolutionInn App