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.
-
Y = 1/3x
-
Three identical small spheres, each of weight 2 lb, can slide freely on a horizontal frictionless surface. Spheres B and C are connected by a light rod and are at rest in the position shown when...
-
A diesel cycle operates at a pressure of 1 bar at the beginning of compression and the volume is compressed to \(1 / 15^{\text {th }}\) of the initial volume. Heat is supplied until the volume is...
-
In this exercise, you modify the Chopkins Toys application from Exercise 11. Use Windows to make a copy of the Chopkins Solution folder. Rename the copy Modified Chopkins Solution. Open the Chopkins...
-
The loading Code AS1170.1 requires that the reading room (without a bookstore) at the library be designed for a floor live load of Q = 2.5 kPa. If the spans between two steel beams are L = 12 m as...
-
A bumper, consisting of a nest of three springs, is used to arrest the horizontal motion of a large mass which is traveling at 40 ft/sec as it contacts the bumper. The two outer springs cause a...
-
Suppose there is a deli with 4 sandwiches, 2 sides, 2 sodas and 3 juices. How many different ways can you order one sandwich, two unique sides and a drink (where a drink is either a soda or a juice)
-
You are going to loan money to your brother-in-law. He is borrowing $1000 for six months. You have learned that the value of money may go down and buy less in the future. You decide to charge your...
-
How different the political and economic status quo is now that Biden and the Democrats have won the executive branch?
-
There are three main economic goals shared by countries around the world: growth, high employment, and price stability. Choose a country to examine further. Using reputable online resources, explain...
-
Best Construction purchased a delivery truck on June 1 , 2 0 2 4 . The following information is available: Cost = $ 9 0 , 0 0 0 Estimated service life = 5 years Estimated residual value = $ 1 5 , 0 0...
-
Game theory is a very promising technique to achieve optimal outcomes and can be applied to almost all concepts, including independent decision-making. Keeping the concepts of game theory, discuss...
-
a. One tool of corporate governance is monitoring management. b. One tool of corporate governance is the choice of how much dividends to pay. c. Corporate governance is better when Directors are also...
-
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...
-
Briefly explain the difference between accounting, finance, and engineering economics. Try to put the concepts in your own (or your team's) words and compare the concepts where appropriate.
-
What are the two key financial objectives in the management of a company? How can a focus on these objectives create ethical dilemmas?
-
Among your colleagues in class, identify a term or phrase italicized in this chapter that you think is the most significant from your reading. Absent team consensus, then just provide your...
Study smarter with the SolutionInn App