
Use Java
Implement a game of Pig where the user plays against a "hold at 20 or goal" computer player that rolls until a 1 ("pig") is rolled, or the turn total is greater than or equal to 20, or the score plus the turn total is greater than or equal to 100. The first player is chosen randomly.
An empty input (i.e., Enter) indicates that the user wishes to roll. Any entered line of non-zero length indicates that the user wishes to hold.
- Before the game, randomly select which player the user will be, and print the line "You will be player #.", where # is the user's player number. Then, print an instruction line "Enter nothing to roll; enter anything to hold."
- Before each turn, print a line with "Player 1 score: " and player 1's score. Print another line with "Player 2 score: " and player 2's score. Finally, print a line with "It is player #'s turn.", where "#" is replaced by the current player number. Play starts with player 1 and then alternates.
- For each roll, print a line with "Roll: " and the random die roll value (1-6).
- For each non-"pig" roll 2-6 on the user's turn, prompt the user with "Turn total: ", the turn total, a tab, and "Roll/Hold? ".
- After a "pig" roll of 1, or a "hold", print a line with "Turn total: " followed by the turn total. In the case of a "pig", this turn total is 0. Then, print a line with "New score: " followed by the new score for the current player
Sample Transcript (input underlined):
You will be player 2.
Enter nothing to roll; enter anything to hold.
Player 1 score: 0
Player 2 score: 0
It is player 1's turn.
Roll: 5 Roll: 3 Roll: 5 Roll: 1 Turn total: 0 New score: 0
Player 1 score: 0 Player 2 score: 0
It is player 2's turn.
Roll: 6
Turn total: 6
Roll/Hold? (Enter)
Roll: 5 Turn total: 11
Roll/Hold? (Enter)
Roll: 6
Turn total: 17
Roll/Hold? (Enter)
Roll: 2
Turn total: 19
Roll/Hold? (Enter)
Roll: 2
Turn total: 21
Roll/Hold? h
Turn total: 21
New score: 21
Player 1 score: 0
Player 2 score: 21
It is player 1's turn.
Roll: 5 Roll: 6 Roll: 3 Roll: 5 Roll: 1
Turn total: 0 New score: 0
Player 1 score: 0 Player 2 score: 21
It is player 2's turn.
Roll: 6 Turn total: 6
Roll/Hold? (Enter)
Roll: 6 Turn total: 12
Roll/Hold? (Enter)
Roll: 2
Turn total: 14
Roll/Hold? (Enter)
Roll: 6
Turn total: 20
Roll/Hold? h
Turn total: 20
New score: 41
Player 1 score: 0
Player 2 score: 41
It is player 1's turn.
Roll: 3 Roll: 3 Roll: 6 Roll: 4 Roll: 4 Turn total: 20
New score: 20
Player 1 score: 20 Player 2 score: 41 It is player 2's turn. Roll: 3 Turn total: 3 Roll/Hold? (Enter) Roll: 3 Turn total: 6 Roll/Hold? (Enter) Roll: 2 Turn total: 8 Roll/Hold? (Enter) Roll: 2 Turn total: 10 Roll/Hold? (Enter) Roll: 4 Turn total: 14 Roll/Hold? (Enter) Roll: 2 Turn total: 16 Roll/Hold? (Enter) Roll: 4 Turn total: 20 Roll/Hold? h Turn total: 20 New score: 61 Player 1 score: 20 Player 2 score: 61 It is player 1's turn. Roll: 5 Roll: 1 Turn total: 0 New score: 20 Player 1 score: 20 Player 2 score: 61 It is player 2's turn. Roll: 3 Turn total: 3 Roll/Hold? (Enter) Roll: 3 Turn total: 6 Roll/Hold? (Enter) Roll: 5 Turn total: 11 Roll/Hold? (Enter) Roll: 2 Turn total: 13 Roll/Hold? (Enter) Roll: 6 Turn total: 19 Roll/Hold? h Turn total: 19 New score: 80 Player 1 score: 20 Player 2 score: 80 It is player 1's turn. Roll: 3 Roll: 1 Turn total: 0 New score: 20 Player 1 score: 20 Player 2 score: 80 It is player 2's turn. Roll: 2 Turn total: 2 Roll/Hold? (Enter) Roll: 2 Turn total: 4 Roll/Hold? (Enter) Roll: 4 Turn total: 8 Roll/Hold? (Enter) Roll: 2 Turn total: 10 Roll/Hold? (Enter) Roll: 3 Turn total: 13 Roll/Hold? (Enter) Roll: 6 Turn total: 19 Roll/Hold? (Enter) Roll: 5 Turn total: 24 Roll/Hold? h Turn total: 24 New score: 104

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps

- in Java Tasks Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Don't display the computer's choice yet.) 2. The user enters his or her choice of "rock", "paper", or "scissors" at the keyboard. (You can use a menu if you prefer.) 3. The computer's choice is displayed. Tasks 4. A winner is selected according to the following rules: a. If one player chooses rock and the other player chooses scissors, then rock wins. (The rock smashes the scissors.) b. If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cuts paper.) C. If one player chooses paper and the other player chooses rock, then paper wins. (Paper wraps…arrow_forwardJava Programming: Write a command line game that plays a simple version of blackjack. The program should generate random numbers between 1 and 10 each time the player gets a card. It should keep a running total of the players cards, and ask the player whether or not it should deal another card. Sample output for the game is written below. Your program should produce the same output. The players get two cards to start with. Then they are asked if they want more cards. Players can continue to take as many cards as they like. The goal is to get close to 21 without going over. If the total is greater than 21 we say the player "busted".arrow_forwardIn Javaarrow_forward
- in java Strings itemToFind and inputItem are read from input. Integer wordCount is initialized with 1. Write a while loop that iterates until inputItem is equal to "Done". In each iteration of the loop: Increment wordCount if inputItem is equal to itemToFind. Read string inputItem from input. Click here for example Note: Assume that input has at least two strings. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import java.util.Scanner; public class SimpleWhileLoop { publicstaticvoidmain(String[] args) { Scannerscnr=newScanner(System.in); StringitemToFind; StringinputItem; intwordCount; itemToFind=scnr.next(); inputItem=scnr.next(); wordCount=1; /* Your code goes here */ System.out.println(itemToFind+" occurs "+wordCount+" time(s)."); } }arrow_forwardDesign a program that simulates the slot machine game. When the program starts, it should greet user and then start the game. For each game, the program asks user for the bet amount, and then randomly picks three words/images. If all the three words/images are same, user won three times of the bet amount, if any two of them are same, user won twice of the bet amount, otherwise, user won 0. The program should allow user to play as many games as wanted at one run. The program should display number of games user played, total amount bet and won at the end the program. It should also display each game's information, including game number, bet amount, the three words/images, and won amount. Here is the list of words you may use: Cherries, Oranges, Plums, Bells, Melons, and Bars. i need to do this in raptor flowchartarrow_forwardJava: Receives a phrase and returns the converted phrase to Pig Latin. A word is translated into Pig Latin according to the following rules: a. If there are no vowels in the word, then add “ay” to the end of it. (a, e, i, o, and u are all the vowels considered). b. If the word begins with a vowel, then add “yay” to the end of it. c. Otherwise, take all the letters up to the first vowel and move those letters to the end then add “ay”. Sample Input: System.out.println(toPigLatin("I am fluent in Pig Latin")); System.out.println(toPigLatin(“Hey”)); Sample Output: Iyay amyay uentflay inyay igPay atinLay Heyayarrow_forward
- Accumulating Totals in a Loop Summary In this lab, you add a loop and the statements that make up the loop body to a Java program that is provided. When completed, the program should calculate two totals: the number of left-handed people and the number of right-handed people in your class. Your loop should execute until the user enters the character X instead of L for left-handed or R for right-handed. The inputs for this program are as follows: R, R, R, L, L, L, R, L, R, R, L, X Variables have been declared for you, and the input and output statements have been written. Instructions Ensure the file named LeftOrRight.java is open. Write a loop and a loop body that allows you to calculate a total of left-handed and right-handed people in your class. Execute the program by clicking Run and using the data listed above and verify that the output is correct.arrow_forwardJava question Write a program that plays the Rock-Paper-Scissors game againstthe computer. When played between two people, each personpicks one of three options (usually shown by a hand gesture) atthe same time, and a winner is determined. In the game, Rockbeats Scissors, Scissors beats Paper, and Paper beats Rock. The program should randomly choose one of the three options (with-out revealing it), then prompt for the user's selection. At that point, the program reveals both choices and prints a statementindicating if the user won, the computer won, or if it was a tie.Continue playing until the user chooses to stop, then print thenumber of user wins, losses, and ties.arrow_forwardPrimeAA.java Write a program that will tell a user if their number is prime or not. Your code will need to run in a loop (possibly many loops) so that the user can continue to check numbers. A prime is a number that is only divisible by itself and the number 1. This means your code should loop through each value between 1 and the number entered to see if it’s a divisor. If you only check for a small handful of numbers (such as 2, 3, and 5), you will lose most of the credit for this project. Include a try/catch to catch input mismatches and include a custom exception to catch negative values. If the user enters 0, the program should end. Not only will you tell the user if their number is prime or not, you must also print the divisors to the screen (if they exist) on the same line as shown below AND give a count of how many divisors there are. See examples below. Your program should run the test case exactly as it appears below, and should work on any other case in general. Output…arrow_forward
- Java - Musical Note Frequenciesarrow_forwardPython tic tac toe. Tic tac toe is a very popular game. Only two players can play at a time. Game Rules Traditionally the first player plays with "X". So you can decide who wants to go with "X" and who wants to go with "O". Only one player can play at a time. If any of the players have filled a square then the other player and the same player cannot override that square. There are only two conditions that may match will be a draw or may win. The player that succeeds in placing three respective marks (X or O) in a horizontal, vertical, or diagonal row wins the game. Winning condition Whoever places three respective marks (X or O) horizontally, vertically, or diagonally will be the winner. Submit your code and screenshots of your code in action. Hints : Have a function that draws the board Have a function that checks position if empty or not Have a function that checks player or won or not expected output:arrow_forwardWrite in Java pleasearrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





