I have an assignment where I have to fill in the blank on a question. I am a beginning student and there are people helping on this website, but the code they are providing includes ideas that I have not learned in class yet. Can someone please help with a way that isn't too complicated or doesn't involve methods that a beginning coder wouldn't know how to do yet?
I am provided with this question class:
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.equalsIgnoreCase(answer);
}
public void display() {
System.out.println(text);
}
}
The question that is presented is: Add a class FillInQuestion to the question hierarchy of How To 10.1. An object of this class is constructed with a string that contains the answer, surrounded by _ _, for example, "The inventor of Java was James Gosling". The question should be displayed as
The inventor of Java was _____
What my teacher wants me to do is, for example, have a string input of "The inventor of Java was James Gosling" and then call this method and have it extract the answer, print the question without the answer, and have a user input an answer and check if its right. I've been working on this for a while and struggling because all the help on the internet uses concepts we haven't talked about in class yet and I am therefore not supposed to use. I am thinking there is possibly a way to do this with a loop? please help!!!!
Aucun commentaire:
Enregistrer un commentaire