在线考试系统JAVA_第1页
在线考试系统JAVA_第2页
在线考试系统JAVA_第3页
在线考试系统JAVA_第4页
在线考试系统JAVA_第5页
已阅读5页,还剩13页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、题目在线考试系统1、实验目的 熟练运用JAVA开发环境及工具、并用JAVA语言编写程序; 掌握面向对象的概念; 掌握系统功能模块的合理划分,并实现各模块接口的连接; 掌握C/S结构的编程方法; 设计数据库模型。2、实验内容 编辑生成试题库,随机生成本次考试试题,同时提供在线评分并保存结果。 选择ACCESS作为后台的数据库。3、实验过程3.1系统模块部分设计 在线考试系统考试 管理试 卷 管 理题 库 管 理评卷管理成绩管理信息管理题库管理:用于对单个试题的增、删、改、查等基本维护,还可对题库进行数据 备份和数据还原。我们针对不同题型、不同应用范围及不同科目对试题进行维护。 试卷管理:可进行三

2、种组卷方式的维护:随机组卷、人工组卷、综合组卷。还可 对考生的基本信息进行维护。考试管理:对考试分配试卷,并对考试的基本信息进行维护。相当于人工安排考 试的过程评卷管理:对试卷的客观题分配评卷人,并对评卷人基本信息进行管理。成绩管理:对每次考试的学生成绩的基本信息进行维护, 并提供学生成绩的统计 管理。用户管理:对使用本系统的用户基本信息进行维护,用户多数为:系统管理员、 老师、教务处人员、其他权限管理:对系统的访问权限进行管理,并对用户可进行权限的分配。系统应该具备的基本功能各模块需完成以下功能:试题其它维护维护题库管理、U-rm试卷官理题型维护:对试题的题型进行 增、删、改、查操作。在操作

3、之后会自动刷新主页, 以使信息更新。范围维护:对试题的应用范围进行 增、删、改、查操作。在操作之后会自动刷新 主页,以使信息更新。科目维护:对试题的科目进行 增、删、改、查操作。在操作之后会自动刷新主页, 以使信息更新。试题维护:对试题的基本信息进行 增、删、改、查操作。在操作之后会自动刷新 主页,以使信息更新。其他维护:对试题信息的批量查询,并可进行数据导出、数据备份、数据恢复。 随机组卷:用户只需对试卷题型进行设置就可组卷的方式。人工组卷:可使用户选择试卷的题型中的试题的组卷方式。综合组卷:是随机组卷与人工组卷的混合组卷方式, 即用户对某一类型的试题可 进行选择,也可对试题不进行选择。试卷

4、其他维护:对试卷信息的批量查询,对试题的数据备份与还原。考试信息维护:对考试的时间、地点、监考人、考试用的试卷、试卷总分数及答 卷总时间等考试的基本要素进行设置。考生信息维护:对考试的学生的基本信息进行增、删、改、查 操作,在操作之后 会自动刷新主页,以使信息更新。分配评卷人:对考试所用试卷的客观题分配评卷人, 并对评卷的基本信息进行维 护。评卷人评卷:对分配试卷的评卷人可以在此进行评卷。考生成绩维护:对考试的考生成绩信息进行统计与汇总, 对有权限的人可进行成绩的增、删、改、查操作。成绩其他维护:对考生成绩信息的批量查询,并可进行数据导出、数据备份、数 据恢复。信息管理信息基本维护用户基本信息

5、维护:对使用本系统的用户进行维护,而用户的权限由权限管理进 行维护,并分配给用户,使用户只能访问自己拥有的权限内。权限信息维护:对基本的权限进行维护,用户可自定义维护权限。用户分配权限:对未分配权限的用户进行权限的分配,即对分配权限的增、删、 改、查操作。信息基本维护:我们的信息除了有关考试的信息外,还有公告、新闻、留言信息 需要我们维护,其中公告、新闻由后台有权限的人进行增、删、改、查操作,而留言是由前台的用户(学生)或游客录入的,我们要防止垃圾数据显示,即对留 言有权更改等操作。3.2系统结构图0、本系统分为学生前台子系统和考试管理子系统,整个系统的结构图如下:3.3 数据库设计 试题类型

6、表 (questionType_table) :其中包括了试题的类型的基本信息,如类型 名称、答题方式、说明信息等字段;录入时,我们将答题方式确定为大概几种类 型:填空方式,选择方式,问答方式,判断方式,综合方式。试题范围表 ( questionBound_table ) :用于控制试题应用的范围,如同样的科目 语文,在小学、初中、高中、大学都有,由此我们设定了此表,此表中有范围名 称、范围说明等基本信息;所属科目表 (questionSubject_table) :用于录入试题相关的科目应用,它可以 有不同的应用范围。如上所述,我们只需录入一次的科目,就可方便我们在录入 试题时每次都录。各种

7、题库表:我们采用一种类型的题存储在一个表中,由此我 们会有填空题表( question_blanc_table )、单选题表( question_selectone_table )、多选题表( question_selectMany_tabel )一 题多问表 (question_askone_table) 、一题多问表 (question_askMany_table) 、 判断题表( question_judge_table )等试题表试卷表 (exam_table) :用于报存考试中试卷的基本信息,如出卷方式 (有随机出 卷、人工出卷、综合出卷)、试卷名称、试卷应用范围(与试题范围相对应)

8、、 试卷所属科目(与试题科目相对应) 、试题标题级别、试题标题内容、试题总类 型、试题个数、试题总 ID 等基本信息。学生表 (student_table) :用于保存学生的考试的用户名及登陆密码。成绩表 (grade_table) :用于存储学生的考试成绩。评题表 (appraiser_question_table) :对于主观题的答案我们须要评卷人 (有权 限的用户)进行手工评卷,本表用来存储评卷人评卷的一些信息。答案表 (student_answer_table) :用于存储学生问答题的答案,如试卷 ID ,学 生 ID 及各种试题类型的答案字段。用户表 (user_table) :用于

9、保存用户的登陆的基本信息及分配的权限。权限表 (purview_table) :用于存储用户组织的的权限,通过分配操作模块的权 限组织权限。4、关键代码及其分析4.1ServerGui.javapublic void actionPerformed(ActionEvent e) if (e.getSource() = log) / boolean b=login();String username = JOptionPane.showInputDialog(this, 请 输入用户名 , 输 入 用 户 名 ,JOptionPane.QUESTION_MESSAGE).trim();Strin

10、g password = JOptionPane.showInputDialog(this, 请 输入密码 , 输 入 密 码 ,JOptionPane.QUESTION_MESSAGE).trim();if (username = null | password = null) username = temp;password = temp; return;adminCheck(username,password);/ 验证管理员if (tf = true) else JOptionPane.showMessageDialog(this, 你还没有设置考试信息 , 警告信息 ,JOption

11、Pane.INFORMATION_MESSAGE);JOptionPane.showMessageDialog(thi s, 登陆成功! , 成功,if (start = true)JOptionPane.INFORMATION_MESSAGE);toolBar1.setVisible(true);linkArea.append(ServerManager.linkShow(ServerManager.linkstatusplit_one.setVisible(true); else s)+ n);JOptionPane.showMessageDialog(thi else s, 登陆失败!

12、, 失败,JOptionPane.showMessageDialog(thiJOptionPane.ERROR_MESSAGE);s, 服务器还没有启动不能进行操作 , 警return;告信息 , else if (e.getSource()=JOptionPane.INFORMATION_MESSAGE);setCount) userCount=JOptionPane.showInputDialog(this,请 else if (e.getSource() =输入本次考试的人数 );userButton) inittest();/数据库信息初始化if (start = true) else

13、 if (e.getSource() = startSer) if (settime = true & setcount = true) new ServerManager();serArea.append( 服 务 器已启动 n 预设考试人数为 : + userCount + n 考试时间为: + timeCount + n);userArea.append(ServerManager.userShow(ServerManager.userstatus)+ n);userArea.append(ServerManager.countShow(ServerManager.ucount);sta

14、rt = true; else publicadminCheck(String s1, String s2)voidConn ectBea nConn ectBea n();cb=newif (!cb.ope nConnection() System.out.println(”连接数据失败);System.exit(1);return;Strin gToke ni zerst=new4.2Server_login .java/定义一个接收用户登陆的类 public void run() String s = n ull;try s = in .readUTF(); /接收考试号和密码,然后分别

15、取出Strin gToke ni zer(s, ,);if (st.hasMoreT okens() str1 = st. nextToke n();str2 = st. nextToke n();System.out.pri ntl n(user name:+str1);System.out.pri ntl n(password:+str2); catch (IOExcepti on e) e.pri ntStackTrace();System.out.pri ntl n(连接 数据失败);System.exit(1);return;cb.createPreparedStateme nt(s

16、elect flag from stu info where sno=+ str1 + ResultSetrcb.executeQuery(); |Stri ng m =; while (r.n ext() m=r.getStri ng(flag);System.out.println(”标识+m);if ( !m.equals(0) ) out.writeUTF(用户已经完成考试,不能再考试); else cb.createPreparedStateme nt(select/读取数据库里的用户信息并进行验证try Conn ectBea ncb = newConn ectBea n();if

17、 (!cb.ope nConnection() sn ame,spass from stu info where sno= + str1false);ResultSetrsmilcb.executeQuery();while (rs.next() update*卄1+stuinfo1.set flag = 1 wheresno=dbn=rs.getStri ng(s name);PreparedStateme ntdbp=ps = cb.createPreparedStateme nt(sql1);rs.getStri ng(spass);System.out.pri ntl n(ps.exe

18、cuteUpdate();用户:+ str1 + 你的用户名为:” + dbnSystem.out.pri ntl n(+ ,你的用户成功登录);密码为:+ dbp);Jelse /验证用户密码,如果登录成功将登录标志设为1out.writeUTF(密码if错误);(str2.equals(dbp.trim() System.out.pri ntl n(out.writeUTF(” 用户登陆密码错误);+ dbn + 登陆成功);System.out.pri ntl n(out.close();用户 ” + dbn + 登陆成功);out.close();cb.close();Stri ngs

19、ql1=4.3-ServerManager.java-public ServerMa nager() the port: + portl;Thread td1 = new Thread() serShow(serstatus);public void run() start!n;serstatus= login thread serShow(serstatus);ServerSocket ss1 = n ull; Socket you = n ull;in t port1 = 8001;try catch (IOExceptio n e) e.pri ntStackTrace();while

20、(true) try youss1 = new ss1.accept();ServerSocket(port1);catchserstatus = liste ner(IOException e) e.pri ntStackTrace();if (you != n ull) coun ter+;ucount =现在 参加考试的人数为:+ cou nter;coun tShow(uco un t);if (co un terMaxcou nt) userstatus=usersyou.getI netAddress()IP+connected + port1 + 进行登陆;userShow(us

21、erstatus);第一个 线程启动newServer_logi n(y ou).start(); else userstatus=users IP + you.get In etAddress()+connected + port1 + 中断线程启动;userShow(userstatus);/中断线 程启动newMaxco un ter(you);td1.start();/启动一个响应客户端读取试题 的线程Thread td2 = new Thread(two) public void run() serstatus= thread 2start!;serShow(l in kstatus

22、); ServerSocket ss2 = nu II;int port2 = 8002;try ss2 = new ServerSocket(port2);lin kstatus=liste ner the port: + port2;lin kShow(serstatus); catch (IOExceptio n e) e.pri ntStackTrace();while (true) Socket you2 = n ull; try you2=ss2.accept();catch(IOException e) e.pri ntStackTrace();if (you2 != n ull

23、) userstatus =users IP + you2.get In etAddress()+connected + port2 + 进行读题;1userShow(userstatus);newServer_readTest(you2).start();if (you3 != n ull) ;td2.start()+IIconnected + port3 + 提交答案;userstatus=usersIP+you3.getl netAddress()/启动一个接收用户答应并存储 的线程Thread td3 = new Thread(three) ServerSocket ss3 = nu

24、II; |in t port3 = 8003;public void run() serstatus=thread3start!;serShow(serstatus);try ss3 = newServerSocket(port3);li nkstatus=liste ner the port: + port3;lin kShow(li nkstatus); catch (IOExcepti on e) e.pri ntStackTrace();while (true) Socket you3 = null;try you3=ss3.accept();catch(IOException e)

25、userShow(userstatus);丨 , 第3个线程 启动newServer_readScore(you3).start();td3.start();/启动一个用户查询的线程Thread td4 = new Thread(four) ServerSocket ss4 = n ull;in t port4 = 8004;public void run() serstatus=thread4start!;serShow(serstatus);try ss4 = new ServerSocket(port4);lin kstatus=liste ner the port: + port4;l

26、in kShow(li nkstatus); catch (IOExceptio n e) e.pri ntStackTrace();e.pri ntStackTrace();while (true) Socket you4 = n ull;if (you4 != n ull) try userstatus=usersIPyou4.getI netAddress()+you4=ss4.accept();+ catchconnected + port4 + 进行查询;(lOException e) 1userShow(userstatus);e.pri ntStackTrace();4.4 Se

27、rver_readTest.javapublic void run() Stri ng sql2; / 定义查询语句String dbt =以下为试题;/试题 String ts = n ull; II接收用户发送的 考试科目int tcou nt = 0; II 试题的数目try II网络连接部分out.writeUTF(” 你连接成功);ts = in. readUTF();System.out.pri ntl n( ts);II数据库连接部分II查询客户端所选试题Conn ectBea ncb = newConn ectBea n();if (!cb.ope nConnection()

28、System.out.pri ntl n(连接 数据失败);System.exit(l);return;II在数据库选题sql2 = select * from exam where eid= + ts + ; |cb.createPreparedStateme nt(sql2, false);ResultSetrs=cb.executeQuery(); |while (rs.next() dbt+=A+n+rs.getStri ng(2) +t + n+rs.getStri ng(3) +A;tco un t+;cb.close();System.out.pri ntln( dbt);Sys

29、tem.out.pri ntln (tco un t);out.writeUTF(I nteger.toStri ng(tco un t)5out.writeUTF(dbt); II 将读到的试题返回到客户端II传送考试时间out.writeUTF(+Timecou nt);out.flush();out.close();System.out.pri ntln(” 读取试题 成功! !); catch (SQLException e) e.pri ntStackTrace();System.out.pri ntln ( notconnect db); catch (IOException e1

30、) System.out.pri ntln (” not read clie nt select!);4.5 /Server readScore.java /定义一个接收用户答案的类,判断对错,将分数返回到用户端,并将成绩存入数据库public Server_readScore(Socket socket) / 创建网络连接/this.socket = socket;public void run() / 接收用户提交的答案/try readkey = in. readUTF(); System.out.pri ntln( readkey); catch (IOException e1) e1

31、.pri ntStackTrace();str2 = stc. nextToke n().trim();System.out.pri ntln(” 试题类型 为:+ st;/ 在数据库获取正确答案/try Conn ectBea ncb = newConn ectBea n();if (!cb.ope nConnection() System.out.pri ntl n(连接 数据失败);|System.exit(l);return;Strin gToke ni zerstc = newStri ngToke ni zer(readkey, ,);if (stc.hasMoreT okens(

32、) /客户传来答案的第一个字 符为用户名,第二个字符为考试科目stri = stc. nextToke n().trim();System.out.println(” 用户为: + stri);uno = In teger.parse In t(str1);if (stc.hasMoreT okens() /第二个字符为考试科目/ 判 断 分 数/for (i nt i =0; iln teger.parse In t(str4); i+) if(userAnsweri.equals(crreAnsweri) count += 10;System.out.println(” 用户:+ stri

33、 + ,你的得分为:” + cou nt);/将分数返回到客户端try 数据失败);System.exit(1);return;PreparedStateme ntpsout.writeUTF(l nteger.toStri ng(co un t);System.out.pri ntln(” 将分数返 回到客户端);cb.createPreparedStateme nt(subject);out.flush(); out.close();ps.setInt(1, count); | ps.setI nt(2, uno);ps.executeUpdate();System.out.pri ntl

34、n(” 更新成功mit(); | catch (IOExcepti on e) cb.close(); catch (SQLException e) / TODO自动生成 catch块 System.out.pri ntln(” 写入数据 发生错误! ! /n + e);Conn ectBea n();if (!cb.ope nConnection() 寸System.out.pri ntl n(连接4.6Server.javaConn ectBea ncb = newpublic static void main(String args) new Server();慮功4.7TestGui.

35、javapublicvoidaction Performed(Act ionEvent e) if (e.getSource() = calllP) / 呼叫服务器 catch (Excepti on ee)if (socket != null & in != n ull & out != n ull) /消除以往的连接信息try socket.close();pass;Stri nglog in = user + , +in t port1 = 8001;tryin .close();out.close();/建立网络连接socket = new Socket(ip,果连接成功port1);

36、in.readUTF();查询结果queryInfo = 得到otherinfo.setText(数据传输错误in = new DataInputStream(socket.getInputStream ();out = new DataOutputStream(socket.getOutputStre am();out.writeUTF(login); catch (IOException ee) / 如果连接失败 ipField.setText( 呼叫 失败 );stateField.setText( 你呼叫没有成功 );int port4 = 8004;try socket = new

37、Socket(ip, port4);in = new DataInputStream(socket.getInputStream ();out = new DataOutputStream(socket.getOutputStre am();out.writeUTF(user); stuinfo.setText( 请求 信息已发送 ); catch (IOException ee) / 如果连接失败 ipField.setText( 呼叫 失败 );stateField.setText( 你呼叫没有成功 );stuinfo.setText( 你呼 叫没有成功 );try String/stui

38、nfo.setText(queryInfo);out.flush();out.close(); catch (IOException e1)/ 出现异常); else if (e.getSource() beginExe) / 生成试题String mgr = (String) subject.getSelectedItem();if (mgr.equals( 英 语 ) / 选择英语 selectT(e); else if (mgr.equals( 数 学) / 选择数学selectT(m);stateField.setText( 你 已 经选择了 + mgr + 试题);testinfo.

39、setText( 你 已 经 选择了 + mgr + 试题);startTest.setEnabled(true);if (socket != null) / else if (e.getSource()startTest) /开始考试port3);innew考试stateField.setText(开始,时钟计时 );timeFlag = true;start(); else if (e.getSource() readNext) / 读下一题目 tempStr1 keyField.getText().trim();uanswer += tempStr1 + ;DataInputStream(socket.getInputStream();out = new DataOut

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论