应该是试卷选项的设计
public class Question {
private String title;
private String[] options = new String[4];
private int[] scores = new int[4];
private Integer answer;
public Question(String[] data) {
this.title = data[0];
this.options[0] = data[1];
this.options[1] = data[2];
this.options[2] = data[3];
this.options[3] = data[4];
this.scores[0] = Integer.parseInt(data[5]);
this.scores[1] = Integer.parseInt(data[6]);
this.scores[2] = Integer.parseInt(data[7]);
try {
this.scores[3] = Integer.parseInt(data[8]);
}catch (Exception e){
System.out.println(title);
}
}
@Override
public String toString() {
return title + " " + options[0] + " " + options[1] + " " + options[2] + " " + options[3] + " "
+ scores[0] + " " + scores[1] + " " + scores[2] + " " + scores[3];
}
public void setOptions(String[] options) {
this.options = options;
}
public void setScores(String[] scores) {
this.scores[0] = Integer.parseInt(scores[0]);
this.scores[1] = Integer.parseInt(scores[1]);
this.scores[2] = Integer.parseInt(scores[2]);
this.scores[3] = Integer.parseInt(scores[3]);
}
public String getTitle() {
return title;
}
public void setAnswer(int answer) {
this.answer = answer;
}
public String getOptions(){
return "A." + options[0] + " B." + options[1] + " C." + options[2] + " D." + options[3];
}
public String getOption(int index){
switch (index){
case 0:return "A." + options[index];
case 1:return "B." + options[index];
case 2:return "C." + options[index];
case 3:return "D." + options[index];
}
return null;
}
public int getScore(){
if (answer != null){
return scores[answer];
}
return -1;
}
}