今天的一道面试题,湖南青果软件

zhou1862324 2008-03-18 03:34:42
设计一份考试程序,包含四道单选题和四道多选题,单选题答对一道得1分,多选答对一道得1.5分,
要求学生能在程序的指导下做题,一直得到最终的分数。
要求用JAVA实现。运用面向对象的方式,至少包含试卷,问题,答案三个类。



import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.font.*;
import java.util.*;
import java.io.*;
public class Exam {
public static void main(String[] args) {
JFrame f = new ExamFrame();
f.setVisible(true);
}
}


class ExamFrame extends JFrame {
static int singlequestion;
static int singleanswer;
static int multiplyquestion;
static int multiplyanswer;
static {
Properties prop = new Properties();
try {
prop.load(new FileInputStream("exam.properties"));
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
singlequestion = Integer.parseInt(prop.getProperty("singlequestion"));
singleanswer = Integer.parseInt(prop.getProperty("singleanswer"));
multiplyanswer = Integer.parseInt(prop.getProperty("multiplyanswer"));
multiplyquestion = Integer.parseInt(prop.getProperty("multiplyquestion"));
}
Question[] qs = new Question[singlequestion];
Question2[] q2s = new Question2[multiplyquestion];
Score score = new Score();
int rightcount;
JLabel scoreLabel = new JLabel();
public ExamFrame() {
setSize(600,700);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(12,1));
JPanel titlePanel = new TitlePanel();
add(titlePanel);
Scanner scan = null;
try {
scan = new Scanner(new File("exam.txt"));
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
int index=0;
while(scan.hasNextLine()&&index <singlequestion) {
String temp = scan.nextLine(); //System.out.println(temp);
String[] temps = temp.split("!");
Answer[] answers = new Answer[singleanswer];
ButtonGroup group = new ButtonGroup();
for(int i = 1;i <5;i++) {
answers[i-1] = new Answer(temps[i]);
group.add(answers[i-1]);
}
qs[index] = new Question(temps[0],score,answers);
qs[index].setRightAnswer(Integer.parseInt(temps[5]));
add(qs[index++]);

}
index = 0;
while(scan.hasNextLine()) {
String temp = scan.nextLine();
String[] temps = temp.split("!");
Answer2[] answer2s = new Answer2[multiplyanswer];
for(int i=1;i <7;i++) {
answer2s[i-1] = new Answer2(temps[i]);
}
q2s[index] = new Question2(temps[0],score,answer2s);
int answersize = temps.length - 7;
int[] rightanswers = new int[answersize];
int index2 = 0;
for(int i = 7;i <temps.length;i++) {
rightanswers[index2++] = Integer.parseInt(temps[i]);
}
q2s[index].setRightAnswers(rightanswers);
add(q2s[index++]);
}
JPanel buttonPanel = new JPanel();
JButton submit = new JButton("Submit");
add(buttonPanel);
buttonPanel.add(submit);
submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
EventQueue.invokeLater(new Runnable() {
public void run() {
for(Question temp:qs) {
if(temp.check()) {
rightcount+=1;
temp.score();
}
}
for(Question2 temp2:q2s) {
if(temp2.check()) {
rightcount+=1;
temp2.score();
}
}
scoreLabel.setText("you gave "+rightcount+" right answer,\r\n you got "+score.getResult()+" point");
add(scoreLabel);
rightcount = 0;
validate();
}
});
}
});
}
}


...全文
2299 51 打赏 收藏 转发到动态 举报
写回复
用AI写文章
51 条回复
切换为时间正序
请发表友善的回复…
发表回复
nichc 2008-04-26
  • 打赏
  • 举报
回复
萨地方
zhou1862324 2008-04-15
  • 打赏
  • 举报
回复
ding!
zhou1862324 2008-04-07
  • 打赏
  • 举报
回复
是的,也可以用J2EE解决.
用JSP+SERVLET+JAVABEAN就OK了!
pyantking 2008-04-07
  • 打赏
  • 举报
回复
学习,顶
Ant 2008-04-07
  • 打赏
  • 举报
回复
俺也是湖南人,所以鼓励鼓励,呵呵!

没事多写写程序,动动手,把基础打牢固,加油!
token1984 2008-04-07
  • 打赏
  • 举报
回复
学习中
zhou1862324 2008-04-03
  • 打赏
  • 举报
回复
长沙有几家还算可以,包括青果软件在内,
但总的来说行业环境并不是太好.
你还是学生吧?
[Quote=引用 40 楼 hunsilj 的回复:]
学习啦

我天津的长沙人,还不知道长沙有哪些好公司,呵呵!
[/Quote]
onif 2008-04-03
  • 打赏
  • 举报
回复
你们说当遇到这种题时是不是用j2se(命令行、swing)或 j2ee写都行啊?
zhou1862324 2008-04-03
  • 打赏
  • 举报
回复
还有:拓维股份有限公司
电信下面的子公司创发天辰
中南大学的科创
属于南京在长沙的分点的联创
另外还有几家.
这几家在长沙都还算可以了,呵呵
[Quote=引用 40 楼 hunsilj 的回复:]
学习啦

我天津的长沙人,还不知道长沙有哪些好公司,呵呵!
[/Quote]
Coder211 2008-04-02
  • 打赏
  • 举报
回复
zjhlht 2008-04-02
  • 打赏
  • 举报
回复
关注下~~~~~
hunsilj 2008-04-02
  • 打赏
  • 举报
回复
学习啦

我天津的长沙人,还不知道长沙有哪些好公司,呵呵!
zhou1862324 2008-04-02
  • 打赏
  • 举报
回复
是有点黑,呵呵
[Quote=引用 38 楼 Coolfatman 的回复:]
引用 36 楼 zhou1862324 的回复:
待遇在长沙这种地方还是可以了,刚进去大概2000-3000/月,包中晚餐;
不过他们不要新手,只要能做事能解决问题的程序员.


这也太黑了一点。
[/Quote]
Coolfatman 2008-04-02
  • 打赏
  • 举报
回复
[Quote=引用 36 楼 zhou1862324 的回复:]
待遇在长沙这种地方还是可以了,刚进去大概2000-3000/月,包中晚餐;
不过他们不要新手,只要能做事能解决问题的程序员.
[/Quote]

这也太黑了一点。
xql80329 2008-04-02
  • 打赏
  • 举报
回复
swing 一年不用了 基本忘完了
zhou1862324 2008-04-02
  • 打赏
  • 举报
回复
待遇在长沙这种地方还是可以了,刚进去大概2000-3000/月,包中晚餐;
不过他们不要新手,只要能做事能解决问题的程序员.
zhou1862324 2008-04-02
  • 打赏
  • 举报
回复
safa
NGT_11 2008-03-27
  • 打赏
  • 举报
回复
手写不容易啊
tianyidan 2008-03-27
  • 打赏
  • 举报
回复
8楼的代码很漂亮,随便一划就是这水平,高人啊。
tianyidan 2008-03-27
  • 打赏
  • 举报
回复
你去面试的时候是上机?

我们应该关注代码,其他的东西不谈……我错了。
加载更多回复(31)

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧