Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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()));
   }