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.
-
Verify the entries in Table 5.12 on page 305. Table 5.12 ds (-11-2 5-12 3-8 5-20 -88 k-012345
-
Reconsider Prob. 5110. Using EES (or other) software, investigate the effect of the inner pipe diameter on the rate of heat loss. Let the pipe diameter vary from 1.5 to 7.5 cm. Plot the rate of heat...
-
The payroll disbursements were for two persons named Ciotty and Ciotti with the same first name and address. The interesting observation is that Ciotty is dated February 28, 2019, or after while...
-
The December cash records of Dunlap Insurance follow: Dunlap's Cash account shows a balance of $16,740 at December 31. On December 31, Dunlap Insurance received the following bank statement:...
-
In Figure 32.14, the battery has an emf of 12.0 V, the inductance is L, and the capacitance C is 9.0 pF. The switch has been set to position a for a long time so that the capacitor is charged. The...
-
Calculate payroll. Example provided for the first pay period Project 1 and Project 2 below. Group insurance 30 for each $1,000 FICA-OASID: 6.2% FICA-HI: 1.45% FUTA: 0.6% SUTA: 3.6890% Example1...
-
Let's consider the Loftus Ranches investment decision. Land is $250,000. The brewery building is $1,250,000. The brewing equipment is $1,250,000. Other general start up expenses total $1,000,000. If...
-
What benefits do airlines attempt to obtain through an alliance? Why doesnt an airline simply add the new destinations it wishes to serve instead of entering an alliance?
-
Among the assumptions for the formulation of an LP problem, there is linearity. What does it mean in practice, and why it is important?
-
Provide an example of a domestic alliance and an international alliance.
-
What is sensitivity analysis? Why should sensitivity analysis consider all possible consequences?
-
Quantitative analysis is a. a logical approach to decision making. b. a rational approach to decision making. c. a scientific approach to decision making. d. all of the above.
-
Consider the CAPM. The risk-free rate is 5%, and the expected return on the market is 14%. What is the expected return on a stock with a beta of 1.2?
-
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...
-
Why are we concerned with the distribution of income between whites and blacks, but not between redheads and blondes?
-
Is the class system in the United States more like a pyramid, diamond, or pentagon? Why is this so?
-
Would the Lorenz curve for the world be more or less bowed out compared to the Lorenz curve for the United States?
Study smarter with the SolutionInn App