in this homework i have to do a predicate method that prints a question and then waits for a question. if the user enters no, the method should return false, if the user enters yes the method should return true. I have done that ! but in this part i have problems: if the user enters another thing the program must say something like "wrong answer" and repeat the question. I can't return a string because is a boolean method and i dont know how to resolve this. Thank you!!
import acm.program.ConsoleProgram;
public class YesNo extends ConsoleProgram{
public void run () {
String answer = readLine ("would you like instructions? ");
println (StrBoo (answer));
}
private boolean StrBoo(String answer){
if (answer.equals("yes")) {
return true;
} else if (answer.equals("no")) {
return false;
} else {
return false;
}
}
}
do-whileloop...