📄 paper.java
字号:
package paper;
import java.io.Serializable;
import java.util.Vector;
/**
* @author SpiritRain
*
* paper contains a question set
* and the answer of user
*
*/
public class Paper implements Serializable {
private String pName;
private int questionCount;
private Vector questions;
private Vector userAnswer;
/**
* Create an empty paper with paper name = pName
* @param pName paper Name
*/
public Paper(String pName) {
this.pName = pName;
questions = new Vector();
userAnswer = new Vector();
questionCount = 0;
}
/**
* Appends a question at the end of questions set
* @param q the question to be Appended
*/
public void addQuestion(AbstractQuestion q) {
this.userAnswer.add(null);
this.questions.add(null);
this.setQuestion(questionCount++, q);
}
/**
* calculate total score of user's answer
* @return int of score
*/
public int calScore() {
int score = 0;
for (int i = 0; i < questionCount; i++) {
score += this.getQuestion(i).check(this.getAnswer(i));
}
return score;
}
/**
* get user answer
* @param index user's answer index
* @return user's answer
*/
public AbstractAnswer getAnswer(int index) {
return (AbstractAnswer) userAnswer.get(index);
}
/**
* get key answer
* @param index key answer index
* @return key answer
*/
public AbstractAnswer getKey(int index) {
return getQuestion(index).getKey();
}
/**
* get the Name of paper
* @return String of paper name
*/
public String getName() {
return pName;
}
/**
* get the question at the specified position
* @param index question position
* @return AbstractQuestion
*/
public AbstractQuestion getQuestion(int index) {
// return questions[index];
return (AbstractQuestion) questions.get(index);
}
/**
* return how many questions in the paper
* @return int of question acount
*/
public int getQuestionCount() {
return questionCount;
}
/**
* Replaces the Answer at the specified position with ans
* @param index the positon ans will be placed
* @param ans new AbstractAnswer
*/
public void setAnswer(int index, AbstractAnswer ans) {
this.userAnswer.set(index, ans);
}
/**
* change paper name to name
* @param name new name of the paper
*/
public void setName(String name) {
this.pName = name;
}
/**
* Replaces the Question at the specified position with q
* @param index the positon q will be placed
* @param q new question
*/
public void setQuestion(int index, AbstractQuestion q) {
this.questions.set(index, q);
this.userAnswer.add(null);
if (index > questionCount) {
questionCount = index;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -