怎样用Java制作一个选择题?
package Work1;
public class TestSelect {
public static void main(String[] args) {
Question question=new Question(1, "()是拥有属性和方法的实体。", 5, "AB",
new Select("A", "对象"), new Select("B", "类"), new Select("C", "方法"),
new Select("D", "类的实例"));
System.out.println(question.toString());
}
}
package Work1;
public class Question {
int num;//序号
String timu;//题目
double sccore;//分值
String answer;//答案
Select seA;
Select seB;
Select seC;
Select seD;
public Question(int num, String timu, double sccore, String answer, Select se1, Select se2, Select se3,
Select se4) {
super();
this.num = num;
this.timu = timu;
this.sccore = sccore;
this.answer = answer;
this.seA = se1;
this.seB = se2;
this.seC = se3;
this.seD = se4;
}
@Override
public String toString() {
String tm=num + "、" + timu + "(" + sccore + "分)(答:" + answer + ")";
tm+="\n"+seA;
tm+="\n"+seB;
tm+="\n"+seC;
tm+="\n"+seD;
return tm;
}
}
package Work1;
public class Select {
String title;//选项abcd
String content;//选项内容
public Select(String title, String content) {
super();
this.title = title;
this.content = content;
}
@Override
public String toString() {
return title+":"+content;
}
}
实现效果