Program Description Write a program, CodeCracker.java - another guessing game for two players - but different...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Program Description Write a program, CodeCracker.java - another guessing game for two players - but different from Assignment 1's game. You are going to write a program that generates a 3 digit number at random and let the players guess this code in turns. Each time the player inputs his guess, the program responds with a score reflecting how close the player's guess was from the secret code. At the start, the program should ask for the player's names and do a coin toss to decide who goes first. The objective of the game is for the player to guess the number correctly using the information revealed each turn. You can generate and store the random number in any way appropriate. It's up to you to decide whether you want to represent the random number using Strings or as an integer in the interval [100, 1000). If you want to work with integers, then, of course, you can't have numbers like 071 as possible secret numbers. This is fine. See the Hints section with more information on these two different but equally valid approaches to completing the assignment. Welcome to Code Cracker by <Your name> Enter player 1 name: John Enter player 2 name: Mary Can you crack the code? The computer has thought of a 3 digit number. Flipping a coin to decide who goes first. Mary gets the first turn…. Mary, make a guess: 888 You guessed: 888 You got 0 correct: XXX John, make a guess: 145 You guessed: 145 You got 1 correct: X4X Mary, make a guess: 349 You guessed: 349 You got 2 correct: X49 John, make a guess: 549 You guessed: 549 You got 3 correct: 549 John wins! Bye bye! public static void main(String[] args) { //prints out the introduction to the game System.out.println("Welcome to Code Cracker by "); // This scanner is to input the players name and the guesses. Scanner input= new Scanner(System.in); //Naming the variables. String player1 = ""; String player2 int guess 0; int secretCode=0; int points=0; int turns=0; //This is where the players will type their names. System.out.print("Player 1, enter your name: "); player1= input.next(); System.out.print("Player 2, enter your name: "); 5 6 7 8 9 LO 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 } 29 30 31 32 33 © } 34 } player2=input.next(); System.out.println("Can you crack the code?"); System.out.println("The computer has thought of a three digit number."); // Now seeing who is going to go first. System.out.println("Flipping a coin to decide who goes first"); if (Math.random() <0.50) System.out.println(player1 + " gets the first turn..."); else{ System.out.println( player2 + gets the first turn..." "); System.out.println(); //Making the Secret Code secretCode=(int)(Math.random()*988)+100; A7 ^ Program Description Write a program, CodeCracker.java - another guessing game for two players - but different from Assignment 1's game. You are going to write a program that generates a 3 digit number at random and let the players guess this code in turns. Each time the player inputs his guess, the program responds with a score reflecting how close the player's guess was from the secret code. At the start, the program should ask for the player's names and do a coin toss to decide who goes first. The objective of the game is for the player to guess the number correctly using the information revealed each turn. You can generate and store the random number in any way appropriate. It's up to you to decide whether you want to represent the random number using Strings or as an integer in the interval [100, 1000). If you want to work with integers, then, of course, you can't have numbers like 071 as possible secret numbers. This is fine. See the Hints section with more information on these two different but equally valid approaches to completing the assignment. Welcome to Code Cracker by <Your name> Enter player 1 name: John Enter player 2 name: Mary Can you crack the code? The computer has thought of a 3 digit number. Flipping a coin to decide who goes first. Mary gets the first turn…. Mary, make a guess: 888 You guessed: 888 You got 0 correct: XXX John, make a guess: 145 You guessed: 145 You got 1 correct: X4X Mary, make a guess: 349 You guessed: 349 You got 2 correct: X49 John, make a guess: 549 You guessed: 549 You got 3 correct: 549 John wins! Bye bye! public static void main(String[] args) { //prints out the introduction to the game System.out.println("Welcome to Code Cracker by "); // This scanner is to input the players name and the guesses. Scanner input= new Scanner(System.in); //Naming the variables. String player1 = ""; String player2 int guess 0; int secretCode=0; int points=0; int turns=0; //This is where the players will type their names. System.out.print("Player 1, enter your name: "); player1= input.next(); System.out.print("Player 2, enter your name: "); 5 6 7 8 9 LO 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 } 29 30 31 32 33 © } 34 } player2=input.next(); System.out.println("Can you crack the code?"); System.out.println("The computer has thought of a three digit number."); // Now seeing who is going to go first. System.out.println("Flipping a coin to decide who goes first"); if (Math.random() <0.50) System.out.println(player1 + " gets the first turn..."); else{ System.out.println( player2 + gets the first turn..." "); System.out.println(); //Making the Secret Code secretCode=(int)(Math.random()*988)+100; A7 ^
Expert Answer:
Answer rating: 100% (QA)
This program can be solved using following logic Read player names Generate a random 3 digit integer represented in String format Randomly guess who will go first Loop until a player guess the value c... View the full answer
Related Book For
Financial Accounting A User Perspective
ISBN: 978-0470676608
6th Canadian Edition
Authors: Robert E Hoskin, Maureen R Fizzell, Donald C Cherry
Posted Date:
Students also viewed these programming questions
-
List three specific parts of the Case Guide, Objectives and Strategy Section (See below) that you had the most difficulty understanding. Describe your current understanding of these parts. Provide...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Consider the following molecule: Tin II Chloride(SnCl2) Are the bonds polar or non-polar? Is the molecule polar or non-polar?
-
Sunshine Foods manufactures pumpkin scones. For January 2017, it budgeted to purchase and use 14,750 pounds of pumpkin at $0.92 a pound. Actual purchases and usage for January 2017 were 16,000 pounds...
-
A survey of 2,645 consumers by DDB Needham Worldwide showed that how a company handles a crisis when at fault is one of the top influences in consumer buying decisions, with 73% claiming it is an...
-
Brian Rafferty ingested finasteride, a drug prescribed to him to treat an enlarged prostate. Finasteride is a generic version of Proscar, a drug manufactured by Merck. Some time after he started to...
-
The cash account of Abstract, Inc., disclosed a balance of $16,348.82 on October 31. The bank statement as of October 31 showed a balance of $19,711.75. Upon comparing the statement with the cash...
-
Lets summarize the analysis we carried out in the VC. What is driving economic (GDP) growth in India? What is driving it in China? As you look forward, how does this influence your expectations of...
-
At the end of a recent year, The Gap, Inc., reported total assets of $13,679 million, current assets of $4,516 million, total liabilities of $10,363 million, current liabilities of $3,209 million,...
-
Calculate the number of modes within a bandwidth of 10 nm at the wavelength 600 nm and in a cavity with the volume 1 cm.
-
Health System experienced a 10% net increase in cash flow in 2021. While cash flow increased, the net income declined by 10%. In your own words, what are some reasons this could have occurred? Hint:...
-
Which taxpayer has propertyFor Tax Year 2022, a taxpayer generally may elect to immediately claim up to what amount for the Section 179 deduction? that is depreciable? Kelly owns a townhouse and...
-
Discuss whether capital markets are efficient or not, and how public good news like firm announcing that the actual earnings per share is greater than market expectations would affect the firm's...
-
Using the Percentage of Sales method, you calculated your Cost of Goods Sold to be $5,000, on $20,000 in sales for last month. Using the same method, what will your Cost of Goods Sold be for this...
-
Jeff loaned Mike $8,000, which Mike agreed to repay with interest. Mike is making monthly payments of $350 to Jeff, which includes $50 in interest. How should Jeff report this income? Jim is not...
-
What role does the solvent play in acid-base systems?
-
1) The government decided to reduce taxes on fast-food to increase revenue. The government assumes that fast-food products have a) An inelastic demand b) An elastic demand c) A demand curve that is...
-
Problem 1-38 introduced Lydia Cravette and her florist shop. At the end of May, the following items were in her records: Inventory..$ 1,100 Wages owed to employees 950 Loan owed to the bank. 8,000...
-
Describe what is meant by "value in use" versus "resale value," as applied to capital assets.
-
Peninsula Minerals Ltd.s share capital consists of an unlimited number of common shares, with 9.3 million outstanding. After some early successes, the company has failed to locate new mineral...
-
(a) Show for a 2D Hall bar of length \(L\) and width \(w\) that \(j=\sigma E\) (where \(j\) is the current density, \(E\) is the electric field, and \(\sigma\) is the conductivity) is equivalent to...
-
A European charity has an asset allocation at the beginning of the year consisting of the asset classes and weights shown in Exhibit 11. As Exhibit 11 reveals, the charity has a policy that the asset...
-
Wakuluk is most likely to make significant adjustments to her estimate of the future growth trend for which of the following countries? A. Country Y only B. Country Z only C. Countries Y and Z Neshie...
Study smarter with the SolutionInn App