Skip to content

Instantly share code, notes, and snippets.

@SeanNotman97
Created April 20, 2017 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeanNotman97/57608d01f59ce4643c4ae5b4732f2fde to your computer and use it in GitHub Desktop.
Save SeanNotman97/57608d01f59ce4643c4ae5b4732f2fde to your computer and use it in GitHub Desktop.
Question Class
public class Question implements IDisplayable {
private int questionIdentifier;
private String questionType;
private String theQuestion;
private ArrayList<String> answerOption = new ArrayList<>();
private int selectedAnswer;
public Question(int questionIdentifier, String questionType, ArrayList<String> answer, String theQuestion) {
this.questionIdentifier = questionIdentifier;
this.setquestionType(questionType);
this.theQuestion = theQuestion;
for(String element:answer){
this.addanswerOption(element);
}
if(this.questionType.equals("TF") && (this.answerOption.size() != 2)) {
throw new IllegalArgumentException("Sorry not enough answer options given for True False");
} else if(this.questionType.equals("MC") && (this.answerOption.size() != 4)) {
throw new IllegalArgumentException("Sorry not enough answer options given for Multiple Choice");
} else if(this.questionType.equals("L5") && (this.answerOption.size() != 5)) {
throw new IllegalArgumentException("Sorry not enough answer options given for Likert 5");
}
}
public int getquestionIdentifier() {
return this.questionIdentifier;
}
public void setquestionIdentifier(int questionIdentifier) {
this.questionIdentifier = questionIdentifier;
}
public String getquestionType() {
return this.questionType;
}
public void setquestionType(String questionType) {
if((questionType.equals("TF")) || (questionType.equals("MC") || (questionType.equals("L5")))){
this.questionType = questionType;
} else {
throw new IllegalArgumentException("Sorry please enter, TF, MC, or L5");
}
}
public String gettheQuestion() {
return this.theQuestion;
}
public void settheQuestion(String theQuestion) {
this.theQuestion = theQuestion;
}
public ArrayList<String> getanswerOption() {
return this.answerOption;
}
//orig
//public void addanswerOption(String answerOption) {
// this.answerOption = answerOption;
//}
public void addanswerOption(String answer) {
if(questionType.equals("TF") && (answerOption.size() == 2)) {
answerOption.add(answer);
} else
if(questionType.equals("MC") && (answerOption.size() == 4)) {
answerOption.add(answer);
} else
if(questionType.equals("L5") && (answerOption.size() == 5)) {
answerOption.add(answer);
} else {
throw new IllegalArgumentException("All answers required are given");
}
}
public String toStringanswerOptions() {
String str = "";
for(String elements:answerOption) {
str += elements + ", ";
}
return str;
}
//public void addanswerOption(String answerOption) {
//if(questionType.equals("TF") && (answerOption.size() = 2)) {
//
public int getSelectedAnswer() {
return this.selectedAnswer;
}
public void setSelectedAnswer(int selectedAnswer) {
this.selectedAnswer = selectedAnswer;
}
@Override
public void display() {
}
@Override
public String get() {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment