java学生成绩管理系统课程设计.docx
- 文档编号:26304330
- 上传时间:2023-06-17
- 格式:DOCX
- 页数:44
- 大小:145.53KB
java学生成绩管理系统课程设计.docx
《java学生成绩管理系统课程设计.docx》由会员分享,可在线阅读,更多相关《java学生成绩管理系统课程设计.docx(44页珍藏版)》请在冰豆网上搜索。
java学生成绩管理系统课程设计
简单学生成绩管理系统的设计与实现
1设计目的及内容要求
1、设计目的:
巩固和加深学生对高级语言程序设计课程的基本知识的理解和掌握,掌握java语言编程和程序调试的基本技能,利用java语言进行基本的软件设计,提高运用java语言解决实际问题的能力.
2、内容要求
实现学生成绩的管理(增、删、改、查询、持久化、成绩排序、成绩统计等功能),在文件中增加、删除、学生信息,根据学号查询、修改学生信息,统计功能求每个人的总分并按从高到低排序,通过这些操作对文件中的信息保存。
2系统总体设计
成功登陆系统以后,出现成绩管理界面,系统初始化,可对学生成绩进行增加、删除、查询、修改、统计,进入相应界面进行成绩管理,退出系统自动保存本次操作内容,保存信息。
简易流程图:
3系统详细设计
①
创建Student类,设置变量及对应方法
Student.java代码:
packagekeshe;
importjava.io。
Serializable;
publicclassStudentimplementsSerializable{
privateStringname;
privateintnum;
privateintyuwen;
privateintshuxue;
privateintjava;
privateintsum=0;
publicStudent(){
}
publicStudent(Stringname,intnum,intyuwen,intshuxue,
intjava){
super();
this。
name=name;
this。
num=num;
this。
yuwen=yuwen;
this。
shuxue=shuxue;
this.java=java;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicintgetNum(){
returnnum;
}
publicvoidsetNum(intnum){
this。
num=num;
}
publicintgetYuwen(){
returnyuwen;
}
publicvoidsetYuwen(intyuwen){
this。
yuwen=yuwen;
}
publicintgetShuxue(){
returnshuxue;
}
publicvoidsetShuxue(intshuxue){
this。
shuxue=shuxue;
}
publicintgetJava(){
returnjava;
}
publicvoidsetJava(intjava){
this。
java=java;
}
publicintgetSum(){
returnsum;
}
publicvoidsetSum(intsum){
this.sum=sum;
}
publicStringtoString(){
return"Student[name="+name+",num=”+num+",yuwen=”+yuwen
+”,shuxue=”+shuxue+",java=”+java+”,sum=”+sum
+”]”;
}
}
②
Student管理类StuC,创建对应方法,实现对Student对象的操作(增、删、改、查询、持久化、成绩排序、成绩统计等功能)供其对象调用。
StuC。
java代码
packagekeshe;
importjava。
io。
BufferedReader;
importjava.io.File;
importjava。
io.FileInputStream;
importjava.io.FileNotFoundException;
importjava。
io。
FileOutputStream;
importjava。
io。
FileReader;
importjava.io。
IOException;
importjava。
io。
ObjectInputStream;
importjava。
io。
ObjectOutputStream;
importjava.util.ArrayList;
publicclassStuC{
ArrayList〈Student>al=newArrayList Filefile=newFile(”e: /mydata。 dat”); //添加 publicvoidadds(Students){ al。 add(s); } //删除 publicvoiddel(intn){ for(inti=0;i〈al。 size();i++){ if(al。 get(i)。 getNum()==n) al。 remove(i); } } //求总分 publicvoidsum(){ for(inti=0;i al。 get(i).setSum(al.get(i).getJava()+al.get(i)。 getShuxue()+al.get(i).getYuwen()); } } //排序 publicvoidsort(){ for(inti=0;i size();i++){ for(intj=0;j〈al。 size()-1—i;j++){ if(al。 get(j)。 getSum()〈al。 get(j+1).getSum()){ Objecto=al.get(j); al.set(j,al。 get(j+1)); al。 set(j+1,(Student)o); } } } } publicvoidpaint(){ for(inti=0;i〈al.size();i++){ System.out。 println(al。 get(i)); } } publicStringtoString(){ return”StuC[al=”+al+”]”; } //输出流 publicvoidstor() { ObjectOutputStreamout=null; try{ out=newObjectOutputStream(newFileOutputStream(file)); out.writeObject(al); out.close(); }catch(FileNotFoundExceptione){ e.printStackTrace(); }catch(IOExceptione){ e。 printStackTrace(); } } //输入流 publicvoidread() { ObjectInputStreamin=null; try{ in=newObjectInputStream(newFileInputStream(file)); try{ al=(ArrayList〈Student>)in。 readObject(); }catch(ClassNotFoundExceptione){ al=null; } in。 close(); }catch(FileNotFoundExceptione){ Filefile=newFile(”e: /mydata。 dat”); }catch(IOExceptione){ e.printStackTrace(); } } //查找 publicStudentfind(intn) { for(inti=0;i size();i++){ if(al。 get(i)。 getNum()==n){ returnal。 get(i); } } returnnull; } } ③ 登陆界面及成绩管理的所有界面,同过创建StuC的对象,调用其方法实现成绩管理 代码: packagekeshe; importjava。 awt.*; importjava。 awt。 event。 *; importjava。 io.FileNotFoundException; importjava。 io。 IOException; importjavax.swing。 *; publicclassLoginextendsJFrame{ privateTextFieldf1; privateTextFieldf2; privateJButtonb1; privateJButtonb2; privateJButtonb3; StuCscs=newStuC(); //登陆界面 publicLogin(){ Containercp=getContentPane();//容器 cp.setLayout(newGridLayout(3,1));//三行一列布局 Labell1=newLabel(”用户名"); Labell2=newLabel("密码”); Panelp1=newPanel(); Panelp2=newPanel(); Panelp3=newPanel(); f1=newTextField(10); f2=newTextField(10); f2。 setEchoChar(’*’);//回显字符为* b1=newJButton("登录”); b2=newJButton("重置”); b3=newJButton("退出”); p1.add(l1);//第一行添加label1 p1.add(f1); p2。 add(l2); p2。 add(f2); p3.add(b1); p3。 add(b2); p3.add(b3); cp。 add(p1); cp.add(p2); cp。 add(p3); b1.addActionListener(newEnter()); b2。 addActionListener(newReWrite()); b3。 addActionListener(newClose()); } classEnterimplementsActionListener{ publicvoidactionPerformed(ActionEvente) { if((f1。 getText()).equals(”yazhou")&&(f2.getText())。 equals("123456”)) { scs.read();//初始化,从文件读入信息 XueShengframe1=newXueSheng(); frame1。 setBounds(200,200,300,300); frame1.setVisible(true); } elseJOptionPane.showMessageDialog(null,”用户名或密码错误,请重新登录! "); } } classReWriteimplementsActionListener{ publicvoidactionPerformed(ActionEvente) { f1.setText("”); f2。 setText(””); f1。 requestFocus(); } } classCloseimplementsActionListener{ publicvoidactionPerformed(ActionEvente) { JButtonbt=(JButton)e.getSource(); if(bt==b3){ System。 exit(0); } } } //主函数程序开始 publicstaticvoidmain(String[]args){ Loginlog=newLogin(); log。 setTitle(”系统登录”); log。 setBounds(200,200,300,300); log.setBackground(Color。 blue); log.setVisible(true); } //信息管理界面内部类进行初始化和保存 classXueShengextendsJFrameimplementsActionListener{ privateJButtoncx,zj,tc,sc,xg,tj; publicXueSheng() { Containerc=this。 getContentPane(); c.setLayout(newGridLayout(3,1)); c.setFont(newFont("true",Font.TRUETYPE_FONT,13)); JPanelpanel2=newJPanel(); JPanelpanel1=newJPanel(); JLabellabel1=newJLabel("欢迎进入成绩管理”,SwingConstants.CENTER); label1。 setFont(newFont("true”,Font。 TRUETYPE_FONT,13)); label1.setForeground(Color。 blue); c。 add(label1); //添加按钮 cx=newJButton(”查询"); panel2。 add(cx); zj=newJButton(”增加”); panel2.add(zj); sc=newJButton(”删除”); panel2.add(sc); tc=newJButton("退出”); panel2.add(tc); xg=newJButton(”修改"); panel1.add(xg); tj=newJButton("统计”); panel1。 add(tj); c.add(panel2); c.add(panel1); cx。 addActionListener(this); zj。 addActionListener(this); sc。 addActionListener(this); xg.addActionListener(this); tc。 addActionListener(this); tj。 addActionListener(this); this。 setVisible(true); } publicvoidactionPerformed(ActionEvente) { if(e。 getSource()==cx){ Findf=newFind(); } if(e。 getSource()==zj){ AddFIf=newAddFI(); } if(e。 getSource()==sc){ Deletd=newDelet(); } if(e。 getSource()==xg){ XiuGaix=newXiuGai(); } if(e.getSource()==tc){ shutDown(); } if(e。 getSource()==tj){ Tongjit=newTongji(); } } privatevoidshutDown() { scs.stor(); JOptionPane。 showMessageDialog(null,"信息已保存”); this。 dispose(); } } //增加信息界面内部类,捕获文本框中信息创建Student对象,添加到Arraylist中,如果已存在该学号//给出提示信息,并重新添加. classAddFIextendsJFrameimplementsActionListener{ privateJTextFieldSTNOText,SNAMEText,MAText,CHIText,JAVAText; privateJButtonb1,b2,b3; privateStringSTNO,SNAME,MAT,CHI,JAVA; publicAddFI(){ super(”添加学生信息"); Containerc2=this。 getContentPane(); c2.setLayout(newGridLayout(3,1)); JPanelcenter=newJPanel(newGridLayout(5,2)); JPanellow=newJPanel(newFlowLayout()); JLabellabel1=newJLabel(”添加学生信息",SwingConstants.CENTER); label1。 setFont(newFont(”TRUE”,Font。 TRUETYPE_FONT,20)); c2。 add(label1); STNOText=newJTextField(30);//30列文本框 SNAMEText=newJTextField(30); CHIText=newJTextField(30); MAText=newJTextField(30); JAVAText=newJTextField(30); center。 add(newJLabel("学号”,SwingConstants。 CENTER));//添加标签学号写在标签中间 center.add(STNOText);//添加文本框 center.add(newJLabel(”姓名”,SwingConstants。 CENTER)); center。 add(SNAMEText); center.add(newJLabel("语文”,SwingConstants。 CENTER)); center。 add(CHIText); center.add(newJLabel(”数学”,SwingConstants。 CENTER)); center.add(MAText); center。 add(newJLabel("java”,SwingConstants。 CENTER)); center.add(JAVAText); c2.add(center); b1=newJButton(”添加"); b2=newJButton(”清除”); b3=newJButton(”退出"); low。 add(b1); low.add(b2); low。 add(b3); c2.add(low); //添加监听 b1。 addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); this。 setBounds(200,200,600,400); this。 setVisible(true); this。 setTitle(”添加学生信息”); } publicvoidactionPerformed(ActionEvente){ if(e。 getSource()==b1){ try{ addFI(); }catch(FileNotFoundExceptione1){ e1.printStackTrace(); }catch(IOExceptione1){ e1。 printStackTrace(); } } if(e。 getSource()==b2){ clearForm(); } if(e。 getSource()==b3){ this。 dispose(); } } privatevoidaddFI()throwsFileNotFoundException,IOException{ STNO=STNOText。 getText(); SNAME=SNAMEText.getText(); CHI=CHIText.getText(); MAT=MAText。 getText(); JAVA=JAVAText。 getText(); if(STNO.length()==0||SNAME.length()==0||MAT。 length()==0 ||JAVA。 length()==0||CHI。 length()==0) JOptionPane。 showMessageDialog(this,”请添加完全信息"); else{ Studenta=newStudent(SNAM
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 学生 成绩管理系统 课程设计
![提示](https://static.bdocx.com/images/bang_tan.gif)