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.
-
Suppose that a store carries two different brands, A and B, of a certain type of breakfast cereal. Suppose that during a one-week period the store noted whether each package of this type of cereal...
-
What are the three kinds of testing suggested in the textbook?
-
State the appropriate null and alternate hypotheses for determining whether to conclude that the age distributions differ between the two sites. Exercises 1015 refer to the following data:...
-
a. Prepare line graphs of each of the six expenditure categories. Indicate whether each category appears to be stationary or nonstationary. b. Use Holts method to create models for each expenditure...
-
what could be the solution to Apple's reported Poor suppliers' employees working conditions in China?Exlain
-
CASH PAID FOR MERCHANDISE Guild Company's cost of goods sold for 20-2 was $500,000. Compute the amount of cash paid for merchandise in 20-2. The December 31, 20-2 and 20-1, balances of Merchandise...
-
1) What are the main changes taking place in organizational use of information systems? Which of these do you think is having the greatest impact on businesses? 2)What is the connection between...
-
Find the area of the region enclosed by the parabola ( y = x^2 ) and the line ( y = 4x - 4 ).
-
A continuous random variable ( X ) has a probability density function ( f(x) = kx^2 ) for ( 0 \leq x \leq 1 ) and ( f(x) = 0 ) elsewhere. Find the value of ( k ) and calculate the expected value of (...
-
Two carts on an air track move towards each other with velocities v; and v2i. The carts collide and their velocities vif and v2 are recorded. The table provides data about the collisions including...
-
Use Greens Theorem to evaluate the line integral ( \oint_C (x^2y ,dx + x^2 ,dy) ), where ( C ) is the boundary of the region enclosed by ( y = x^2 ) and ( y = \sqrt{x} ).
-
E xplain why various 8 0 5 1 C compilers produce ddifferent hex file sizes?
-
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...
-
Determine the maximum eccentric load \(P\) the 2014-T6aluminum-alloy strut can support without causing it either to buckle or yield. The ends of the strut are pin connected. a $150 mm 150 mm 100 mm...
-
The W14 \(\times 26\) structural A-36 steel member is used as a column that is assumed to be fixed at its top and pinned at its bottom. If the 15-kip load is applied at an eccentric distance of 10...
-
The W14 \(\times 26\) structural A-36 steel member is used as a 20 -ft-long column that is assumed to be fixed at its top and fixed at its bottom. If the 15-kip load is applied at an eccentric...
Study smarter with the SolutionInn App