Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I made a code to produce a random 3 digit number. I then set up a scanner consol

ID: 3643911 • Letter: I

Question

I made a code to produce a random 3 digit number. I then set up a scanner console for the user to input a number. How would I code this?

The program will print the following words in the given circumstance...
"bagels" -- no digits match between the guess and the answer
"fermi"-- printed for each corret digit in a correct position
"pica" for each correct digit in the WRONG position.

Example Run
--------------------------------------
Your guess? 123
pica pica
Your guess? 456
pica
Your guess? 125
pica
Your guess? 236 <---- fermi is always written first, then picas
fermi pica pica
Your guess? 263
pica pica pica
Your guess? 632
You got it right in 6 guesses.

Do you want to play again? y <---- anything that starts with y
Your guess? 1234
fermi pica
Your guess? 5678
pica
Your guess? 2936
You got it right in 3 guesses.
Do you want to play again? NOPE <---- anything that starts with n
---------------------------------

Explanation / Answer

public static void main(String[] args) { // create random 3 digit number int random = (int)(Math.random()*(999-100))+100; // get user guess Scanner kb = new Scanner(System.in); int numGuesses = 0; System.out.println(random); while(true) { System.out.print("Your guess? "); int input = kb.nextInt(); numGuesses++; // compare digits String temp = ""; int correct = 0; String randomStr = ""+random; String inputStr = ""+input; int i = 0; // look for in place matches while(i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote