How could i re write this method below so that after the print statement \" Syst
ID: 3840925 • Letter: H
Question
How could i re write this method below so that after the print statement " System.out.println("You guessed it right!"); " has been printed it then restarts and asks the user for a new set of coordinates to input. Becuase right now after the user has input the correct set of coordinates it doesnt ask the user for a new word and allow for a new set of coordinate to be guessed ( in java)
public static void play(String thing)
{
System.out.println(" The word is " + thing);
while(true)
{
System.out.println("What coordinate would you like to check (-1 to quit)? ");
int row = getInt();
int column = getInt();
if(things[row][column].getThing().equalsIgnoreCase(thing))
{
System.out.println("You guessed it right!");
}
else
{
System.out.println("Try again!");
System.out.println("You guessed " + things[row][column].getThing());
}
Explanation / Answer
Here is code:
public static void play(String thing) {
System.out.println(" The word is " + thing);
while (true) {
System.out.println("What coordinate would you like to check (-1 to quit)? ");
int row = getInt();
// if user enter -1, breaks the loop
if(row == -1)
break;
int column = getInt();
if (things[row][column].getThing().equalsIgnoreCase(thing)) {
System.out.println("You guessed it right!");
}
else {
System.out.println("Try again!");
System.out.println("You guessed " + things[row][column].getThing());
}
}
}
Any doubts regarding this question comment me
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.