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: 3548439 • 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 variable using Scanner.nextLine() -
under the assumption that the phrase consists of nothing but lowercase letters and spaces.
2. A counter is set to zero.
3. The following is than repeated until the entire "common phrase" is revealed:
The "common phrase" is displayed with all of the letters (that have not yet been correctly
guessed) replaced with the ? character and all of the letters that have been correctly guessed
displayed as is.
Using a user input validation loop, the second user is prompted to enter a single lowercase letter
guess.
A counter is incremented.
4. Once the "common phrase" is revealed, you must also report the total number of valid guesses that
were made to do so.
Requirements
Your program must implement and use the following methods:
public static char getGuess(Scanner stdIn)
This method repeatedly prompts for and obtains a user's char response, until it is in the range of
'a' to 'z' (inclusive) and then returns it.
public static int initTemplateArray(String sPhrase, char [] tmpArr)
This method modies an array argument via the array parameter tmpArr.
It initializes tmpArr to be a template version of sPhrase, that is:
{ At every index where sPhrase is equal to the space character ' ', the element in tmpArr at
that index is set equal to the space character.
{ At every index where sPhrase is not equal to the space character, the element in tmpArr at
that index is set equal to the character '?'
The method also returns the length of sPhrase.
Note: this will be used as the eective size of the Array template in your main method.

public static void printTemplateArray(char [] tmpArr, int tmpArrLen)
This method prints the elements in the tmpArr parameter to the screen.
That is between index 0 and tmpArrLen-1 inclusive.
public static void updateTemplateArray(char [] tmpArr, int tmpArrLen,
. String sPhrase, char guess)
This method modies an array argument via the array parameter tmpArr.
It "reveals" all occurrences of the character guess in the array tmpArr, that is:
{ At every index where sPhrase is equal to the character guess, the element in tmpArr at that
index is set equal to the character guess - replacing the '?' character.
{ At every index where sPhrase is not equal to the character guess, no modication of the element
tmpArr at that index is preformed - leaving the '?' or ' ' character.
public static boolean exposedTemplateArray(char [] tmpArr, int tmpArrLen)
This method returns true if there are no more '?' left un-exposed in tmpArr.
That is between index 0 and tmpArrLen-1 inclusive.
Tips and Hints
You will need to declare / create an array template in your main method, and then pass it into the
various methods above as an argument.
Remember that when an array is passed into a method, that method may both access its elements
(read) and modify its elements (write) by using the subscript operator.

Explanation / Answer

import java.util.Scanner;



public class TakeHomeExam

{

public static void main(String[] args)

{

Scanner stdIn = new Scanner(System.in);

String guess= "";


System.out.print("Please enter the phrase to guess at : ");


String commonPhrase= stdIn.nextInt();


for (int i=0; i < commonPhrase.length(); ++i);


System.out.print (commonPhrase.chartAt(i));


commonPhrase.charAt(i)==


guess.charAt(0)

}

}

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