EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
expand_more
expand_more
format_list_bulleted
Question
Chapter 5, Problem 5GZ
Program Plan Intro
Rock Paper Scissors game
Program plan:
- Import necessary package.
- Create a class “RockPaperScissors”,
- Define the method “main()”,
- Declare and initialize the necessary variables.
- Generate the random value for the computer.
- Assign the integer value returned from the method “parseInt()”.
- Check whether the user value is “1”,
- If it is true set the string as “rock”.
- Otherwise, check whether the user value is “2”,
- If it is true set the string as “paper”.
- Otherwise,
- Set the string as “scissors”.
- Check whether the computer value is “1”,
- If it is true set the string as “rock”.
- Otherwise, check whether the computer value is “2”,
- If it is true set the string as “paper”.
- Otherwise,
- Set the string as “scissors”.
- Check whether the user value is “1”,
- Check whether the computer value is “1”,
- If it is true, set the string as “tie”.
- Otherwise, check whether the computer value is “2”,
-
- If it is true, set the string as “computer”.
- Otherwise, set the string as “you”.
- If it is true, set the string as “tie”.
- Check whether the computer value is “1”,
- Check whether the user value is “2”,
- Check whether the computer value is “2”,
- If it is true, set the string as “tie”.
- Otherwise, check whether the computer value is “3”,
-
- If it is true, set the string as “computer”.
- Otherwise, set the string as “you”.
- If it is true, set the string as “tie”.
- Check whether the computer value is “2”,
- Otherwise, check whether the computer value is “3”,
- If it is true, set the string as “tie”.
- Otherwise, check whether the computer value is “1”,
- If it is true, set the string as “computer”.
- Otherwise, set the string as “you”.
- Display the output message in dialog box.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
When the player clicks on the “Start Game” button, in every 1 seconds, three random alphabets will be generated and flashing on the screen (e.g. A X W) at the position as shown above. The three alphabets must not repeat at the same time (i.e. can’t have repeating alphabets – e.g. A X A). After starting a game, you can’t change the chosen alphabet.
The two friend Alpha and Beta have invented a new game called Coins&Papers. The
game is played with their coins and a strip of paper divided into cells. The cells are
numbered from the left, starting from 1. Alpha and Beta put some coins at some random
cells on the strip, each coin in a cell. They alternatively take their turn to play the game.
At each step, a player must take a coin and move it to a cell to the left of it. There is at
most one coin in a cell at any time of the game. Of course, a coin cannot jump over
another coin. Whoever cannot move loses the game. Beta takes her turn first.
Develop a python code to find out who wins the game, if Beta could win the game,
show her a winning move. If there are several winning moves, show her the winning
move that uses the leftmost possible coin. If there are still several moves, show her the
move that moves the coin as far as possible to the left.
Sample Input:
1
The game is played in the magic maze, as shown below. The squares are flaming lava pools. If you try to cross them you will die. The grid lines are passageways and are safe to travel in.
You can start at any location on the grid but must travel in the passageways. You may travel as far as you want in any direction, but once you turn, you must repeat that distance and you may only make left turns. You may not reverse direction inside the tight passageways. You must end up at the same spot you started at. If you successful, then you gain a magic coin, which automatically appears. You can start over again and again in a different or same starting spot and earn new magic coins, but the routes you take must differ somehow for each magic coin. That is, no magic coins for the exact same route as previously done. If the route varies in any way (perhaps it is the same starting location and ending location as a previous route, but longer), it will earn a new magic coin.
Mad Madame Mim has…
Chapter 5 Solutions
EBK JAVA PROGRAMMING
Ch. 5 - Prob. 1RQCh. 5 - Prob. 2RQCh. 5 - Prob. 3RQCh. 5 - Prob. 4RQCh. 5 - Prob. 5RQCh. 5 - Prob. 6RQCh. 5 - Prob. 7RQCh. 5 - Prob. 8RQCh. 5 - Prob. 9RQCh. 5 - Prob. 10RQ
Ch. 5 - Prob. 11RQCh. 5 - Prob. 12RQCh. 5 - Prob. 13RQCh. 5 - Prob. 14RQCh. 5 - Prob. 16RQCh. 5 - Prob. 17RQCh. 5 - Prob. 18RQCh. 5 - Prob. 19RQCh. 5 - Prob. 20RQCh. 5 - Prob. 1PECh. 5 - Prob. 2PECh. 5 - Prob. 3PECh. 5 - Prob. 4PECh. 5 - Prob. 5PECh. 5 - Prob. 6PECh. 5 - Prob. 7PECh. 5 - Prob. 8PECh. 5 - Prob. 9PECh. 5 - Prob. 10PECh. 5 - Prob. 1GZCh. 5 - Prob. 2GZCh. 5 - Prob. 3GZCh. 5 - Prob. 4GZCh. 5 - Prob. 5GZ
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- In the game Rock paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows: Rock beats scissors, because a rock can break a pair of scissors. Scissors beats paper, because scissors can cut paper. Paper beats rock, because a piece of paper can cover a rock. Create a game in which the computer randomly chooses rock, paper, or scissors. Let the user enter a character, r, p, or s, each representing one of the three choices. Then, determine the winner. Save the application as RockPaperScissors.cs.arrow_forwardThe goal of Snake is to create a snake as long as possible. This is achieved by guiding the snake to an apple on the game board. The snake cannot stop moving, and dies whenever it hits something (excluding apples). Because the snake is growing longer and longer as the game progresses, it gets increasingly difficult to avoid collisions with the snake itself. The player can change the direction of the head of the snake by using the arrow keys. At step in the game, there is always an apple somewhere on the board. If the snake eats an apple, the snake becomes one cell longer. A new apple is placed on a random location, excluding all places covered by the snake. When the snake reaches a side of the game board, it re-emerges at the opposite end.arrow_forwardcreating a roulette wheel. The pockets are numbered from 0 to 36. The colors of the pockets are as follows: Pocket 0 is green. For pockets 1 through 10, the odd-numbered pockets are red and the even-numbered pockets are black. For pockets 11 through 18, the odd-numbered pockets are black and the even-numbered pockets are red. For pockets 19 through 28, the odd-numbered pockets are red and the even-numbered pockets are black. For pockets 29 through 36, the odd-numbered pockets are black and the even-numbered pockets are red. Create a class named RoulettePocket. The class's constructor should accept a pocket number. The class should have a method named getPocketColor that returns the pocket's color, as a string. Demonstrate the class in a program that asks the user to enter a pocket number, and displays whether the pocket is green, red, or black. The program should display an error message if the user enters a number that is outside the range of 0 through 36.arrow_forward
- A number maze is an n × n grid of positive integers. A token starts in the upper left corner; your goal is to move the token to the lower-right corner. On each turn, you are allowed to move the token up, down, left, or right; the distance you may move the token is determined by the number on its current square. For example, if the token is on a square labeled 3, then you may move the token three steps up, three steps down, three steps left, or three steps right. However, you are never allowed to move the token off the edge of the board. 6 3574 5 315 3 283 35 74 6 53 15 1 4 2 8 3 1 4 4 5 7 2 3 4 5 7 2 3 3 1 3 2★ 3 KT3 A 5 × 5 maze that can be solved in eight moves In this problem, you will design and analyze an efficient algorithm that either returns the minimum number of moves required to solve a given number maze, or correctly reports that the maze has no solution. Describe the solution to this problem at a high level, justify why it works, write down the pseudocode for your algorithm…arrow_forwardUsing java card Graphic GUI, create a card game with a card layout in which 13 cards are displayed and if that card has the king of heart, then lose if not the player winsarrow_forwardwhen coding a chess game, implement the following method: isInCheck(Side s): Returns true if the king of side s is attacked by any of the opponent’s pieces, i.e., if in the current board state, any of the opponents pieces can move to where the king is. Otherwise, it returns false. Note that this method is only used to warn the player when they are in check. You can use the GUI to test if this is working. public boolean isInCheck(Side side) { // TODO write this method return false; } public enum Side { BLACK, WHITE; public static Side negate(Side s) { return s == Side.BLACK ? Side.WHITE : Side.BLACK; } }arrow_forward
- Email me the answers to the following questions. If you are not familiar with Peg Solitaire, then look it up online. Peg Solitaire is a game consisting of a playing board with 33 holes together with 32 pegs. In the picture above, the hole in the center is empty and the remaining holes contain pegs. The goal is to remove all the pieces except one, which should be in the center. A piece can be removed by jumping an adjacent piece over it into an empty hole. Jumps are permitted horizontally or vertically, but not diagonally. Your assignment consists of one required part, plus one extra credit part: 1. Explain (in words) why Breadth First Search and Iterative Deepening are not good methods for this problem.arrow_forwardshow how it is executed and the results.arrow_forwardMake this as a python game. In each level it consists of 30 seconds to finish the task and needs to aim 40 points to proceed to the next level. The user should enter or type the incorrect word that doesn't match the color name.arrow_forward
- Who Wants to Be a Millonalre? You are a contestant on "Who Wants to be a Millionaire?" You already have answered the $250,000 question correctly and now must decide if you would like to answer the $500,000 question. You can choose to walk away at this point with $250,000 in winnings or you may decide to answer the S500,000 question. If you answer the $500,000 question correctly, you can then choose to walk away with $500,000 in winnings or go on and try to answer the $1,000,000 question. If you answer the $1,000,000 question correctly, the game is over and you win $1,000,000. If you answer either the $500,000 or the $1,000,000 question incorrectly, the game is over immediately and you take home "only" $32,000. A feature of the game "Who Wants to be a Millionaire?" is that you have three "lifelines"-namely "50-50," "ask the audience," and "phone a friend." At this point (after answering the $250,000 question), you already have used two of these lifelines, but you have the "phone a…arrow_forwardFlashback to Probability: Determine the odds of rolling TWO 6-sided dice, and getting a total between the two dice that is a multiple of three.arrow_forwardChildren often play the game of rock, paper, and scissors. This game has two players, each of whom chooses one of the three objects: rock, paper, or scissors. If player 1 chooses rock and player 2 chooses paper, player 2 wins the game because paper covers the rock. The game is played according to the following rules: If both players choose the same object, this play is a tie. If one player chooses rock and the other chooses scissors, the player choosing the rock wins this play because the rock breaks the scissors. If one player chooses rock and the other chooses paper, the player choosing the paper wins this play because the paper covers the rock. If one player chooses scissors and the other chooses paper, the player choosing the scissors wins this play because the scissors cut the paper. Write an interactive program that allows 1 person to play this game against the computer. Input This program has two types of input: The users’ responses when asked to play the game. The…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY