Modify the checkAnswer method of the Question class of How To 10.1 so that it do
ID: 3843906 • Letter: M
Question
Modify the checkAnswer method of the Question class of How To 10.1 so that it does not take into account different spaces or upper/lowercase characters. For example, the response " JAMES gosling" should match an answer of "James Gosling".
Here is a sample program run:
Use the following class as your main class:
CHECKER PROGRAM - DO NOT MODIFY
import java.util.Scanner;
public class QuestionDemo
{
public static void main(String[] args)
{
Question[] quiz = new Question[2];
quiz[0] = new Question("Who was the inventor of Java?");
quiz[0].setAnswer("James Gosling");
quiz[1] = new Question("What computer device did Douglas Engelbart invent?");
quiz[1].setAnswer("mouse");
Scanner in = new Scanner(System.in);
for (Question q : quiz)
{
q.display();
System.out.println("Your answer: ");
String response = in.nextLine();
System.out.println(q.checkAnswer(response));
}
}
}
Explanation / Answer
In the question I can't find any checkAnswer() Method. But based on your question i understood what is your need. so i created the checkAnswer method. Please look below. It will return true if answer is correct, otherwise it will return false.
Boolean checkAnswer(String response){
if(response.equalsIgnoreCase(q.getAnswer())){
return true;
}
return false;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.