About Java programming, Question.java public class Question { private String tex
ID: 3572116 • Letter: A
Question
About Java programming,
Question.java
public class Question
{
private String text;
private String answer;
public Question()
{
text="";
answer="";
}
public void setText(String questionText)
{
text=questionText;
}
public void setAnswer(String correctResponse)
{
answer=correctResponse;
}
public boolean checkAnswer(String response)
{
return response.toLowerCase().equals(answer.toLowerCase());
}
public void display()
{
System.out.println(text);
}
}
I want modify method checkAnswer ignore spaces.
How to do this?
Explanation / Answer
Below is the updated CheckAnswer Method which should Ignore Space
public boolean checkAnswer(String response)
{
return response.replaceAll("\s+","").toLowerCase().equals(answer.replaceAll("\s+","").toLowerCase()));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.