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

There is a \"fun\" children\'s game where one child thinks of a \"common phrase\

ID: 3642286 • Letter: T

Question

There is a "fun" children's game where one child thinks of a "common phrase", then the second child repeatedly makes guesses as to the letters that it contains.
You are to write a Java program that:

1-Prompts a user to enter a "common phrase", and reads it into a String variable using Scanner.nextLine() - under the assumption that the phrase consists of nothing but undercase letters and spaces.
2-A second String variable, expSoFar, is constructed such that:
It has the same length as the "common phrase".
It contains spaces everywhere that the "common phrase" does.
All its other characters are the '?' character.
3-The following is than repeated until the entire "common phrase" is exposed:
The current value of expSoFar is displayed.
Using a user input validation loop, the second user is prompted to enter a single lowercase letter guess.
The value of expSoFar is modified such that any/all locations where guess occurs in the "common phrase", the '?' character has been replaced with guess.


Requirenments:

You must write and use a method named expose that takes the values of the "common phrase", expSoFar, and guess as input and returns a String that is equal to expSoFar except any/all locations where guess occurred in the "common phrase", the '?' character has been replaced with guess.
public static String expose(String comPhrase, String expSoFar, char guess)
You must write and use a method named done that takes the values of the "common phrase" and expSoFar as input and returns true exactly when all the letters in expSoFar have been exposed.

public static boolean done(String comPhrase, String expSoFar)



Sample run(s):
Please enter the phrase to guess at : who do you love



Common Phrase
-------------
??? ?? ??? ????


Enter a lowercase letter guess : f



Common Phrase
-------------
??? ?? ??? ????


Enter a lowercase letter guess : o



Common Phrase
-------------
??o ?o ?o? ?o??


Enter a lowercase letter guess : s



Common Phrase
-------------
??o ?o ?o? ?o??


Enter a lowercase letter guess : w



Common Phrase
-------------
w?o ?o ?o? ?o??


Enter a lowercase letter guess : h



Common Phrase
-------------
who ?o ?o? ?o??


Enter a lowercase letter guess : d



Common Phrase
-------------
who do ?o? ?o??


Enter a lowercase letter guess : e



Common Phrase
-------------
who do ?o? ?o?e


Enter a lowercase letter guess : y



Common Phrase
-------------
who do yo? ?o?e


Enter a lowercase letter guess : u



Common Phrase
-------------
who do you ?o?e


Enter a lowercase letter guess : l



Common Phrase
-------------
who do you lo?e


Enter a lowercase letter guess : v



Common Phrase
-------------
who do you love

Explanation / Answer

th

uujj


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