Question: Program Description Write a program, CodeCracker.java - another guessing game for two players - but different from Assignment 1's game. You are going to



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 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()
Step by Step Solution
There are 3 Steps involved in it
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 full answer
Get step-by-step solutions from verified subject matter experts
