学生管理系统-java课程设计.doc

上传人:good****022 文档编号:116448590 上传时间:2022-07-05 格式:DOC 页数:45 大小:742.01KB
返回 下载 相关 举报
学生管理系统-java课程设计.doc_第1页
第1页 / 共45页
学生管理系统-java课程设计.doc_第2页
第2页 / 共45页
学生管理系统-java课程设计.doc_第3页
第3页 / 共45页
点击查看更多>>
资源描述
Java程序设计课程期末作业题 目 学生成绩管理系统 学 院 信息科学与工程学院专 业 计算机科学与技术 班 别 09级3班 学 号 200901051624 姓 名 2011年12月17日目录一、课程题目:3二、软件的功能描述3三、系统的UML类图4(一)用况图4(二)类之间的图4(三)数据流程图6四、功能调试6五、具体代码15一、课程题目:设计一个学生Java成绩管理系统(可以不使用界面;如果使用,则界面使用AWT或SWING),要求:a) 增添、删除、修改学生基本信息(基本信息包含学生的学号、姓名、专业分数等信息);b) 计算每门课的平均成绩;c) 统计优秀、良好、中等、及格、不及格的人数百分比,并以柱状图、饼图呈现【说明:可以使用SWING、AWT自己绘制;也可以使用开源类库,如JFreeChar】d) 按学号查询学生及成绩;e) 按照成绩分数排序二、软件的功能描述1, 能够实现学生信息的增删改查四项基本的操作。此程序允许出现重名的现象出现,另外在删除的时候提供了删除所有重名同学的信息和删除指定学号的学生的两种方法,更加贴近现实。2, 能够将程序中的数据存储到data.txt文件中,另外能在程序中通过Swing中的table组件将文件中的内容进行打印出来。可以直观的看到文件内部的结果。3, 此程序给出了“按照学号排序”“按照平均成绩排序”“按照英语成绩排序”“按照数学成绩排序”“按照专业成绩排序”等五个排序方法。4, 此程序在查询的同时又能同时显示出三科成绩的饼图分布,饼图上标出了四个成绩段的人数和百分比。更加方便直观的体现出了单科的成绩分布。5, 程序有一个增加的功能。能够将所有同学的信息用三维柱状图的形式全部呈现出来,能够进行纵向、横向两种比较方式。方便人性化的进行成绩的比较。三、系统的UML类图(一)用况图(二)类之间的图student类 sort类(三)数据流程图四、功能调试1,主界面2,新建学生信息3,查询成绩页面4,修改成绩5,删除成绩第二种方法6, 打印文件内容7, 三科的排序8, 平均成绩排序:9,三科的饼图分布10,所有同学的成绩三维柱状图分析五、具体代码1,主界面代码(Grade.java)public class Grade / 定义主框架private JFrame frame = new JFrame(学生成绩管理系统);/ 定义菜单栏private JMenuBar Bar = new JMenuBar();/ 定义菜单private JMenu JMedit = new JMenu(编辑);private JMenu JMcount = new JMenu(统计);private JMenu JMhelp = new JMenu(数据);/ 定义菜单项private JMenuItem JMIcreate = new JMenuItem(新建);private JMenuItem JMImodify = new JMenuItem(修改);private JMenuItem JMIsearch = new JMenuItem(寻找);private JMenuItem JMIdelete = new JMenuItem(删除);private JMenuItem JMIall = new JMenuItem(成绩排序);private JMenuItem JMIgraphics = new JMenuItem(图形统计);private JMenuItem JMIhelp = new JMenuItem(文件信息);/ 定义文本标签private JLabel text = new JLabel();private JLabel text1 = new JLabel();private JLabel text2 = new JLabel();private JLabel text3 = new JLabel();private JLabel text4 = new JLabel();/ 定义面板private Container con = frame.getContentPane();/ 定义输入框对象/ private StudentManager inputinfo =null;/ 定义查询框架对象private Search search = null;private Create create = null;private Delete delete = null;private Modify modify = null;private Datasort sort = null;private BarCharts ss = null;/ 定义总分统计对象/ private AllgradeCount all = null;/ 定义个人统计对象/ private SignalCount signal = null;/ 构造函数public Grade() / 把菜单栏加入框架frame.setJMenuBar(Bar);/ 把菜单加入菜单栏Bar.add(JMedit);Bar.add(JMcount);Bar.add(JMhelp);/ 把菜单项加入菜单JMedit.add(JMIcreate);JMedit.addSeparator();JMedit.add(JMIsearch);JMedit.addSeparator();JMedit.add(JMImodify);JMedit.addSeparator();JMedit.add(JMIdelete);/ 第一个下拉菜单JMcount.add(JMIall);JMcount.addSeparator();JMcount.add(JMIgraphics);/ 第二个下拉JMhelp.add(JMIhelp);/ 第三个/ 设置文本界面text.setText(=基于TXT文件的Java学生管理系统=);text1.setText(1.增添、删除、修改学生基本信息;并计算每门课的平均成绩;);text2.setText(2.统计优秀、良好、中等、及格、不及格的百分比,并以图呈现);text3.setText(3.按学号查询学生及成绩,并按照不同的成绩分数排序。);text4.setText(=制作者,计算机09-3,王继重=);/ 设置欢迎界面con.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 10);con.add(text);con.add(text1);con.add(text2);con.add(text3);con.add(text4);/ 设置框架frame.setLocation(200, 200);frame.setSize(400, 300);frame.setVisible(true);frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);/ 增加监听器JMIcreate.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) / TODO 自动生成方法存根create = new Create(););JMIsearch.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) search = new Search(););JMImodify.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) modify = new Modify(););JMIdelete.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) delete = new Delete(););JMIall.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) sort = new Datasort(););JMIgraphics.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) ss= new BarCharts(成绩分布柱状图););JMIhelp.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) / TODO 自动生成方法存根/ JOptionPane.showMessageDialog(null, 计算机09-3 王继重);Outfile a = new Outfile(););public static void main(String args) Grade a = new Grade();2,新建用户的代码public class Create extends JFrame /* * 当前容器 */Container currentContainer = this;/* * 存储的文件名 */String fileName = new String(data.txt);/* * 显示标题文本 */JLabel titleLabel = new JLabel(添加成绩界面);/* * 标题面板 */JPanel titlePanel = new JPanel();/* * 显示姓名文本 */JLabel nameLabel = new JLabel(学生姓名);/* * 显示成绩文本 */JLabel scoreLabel = new JLabel(学生学号);JLabel score1Label = new JLabel(英语成绩);JLabel score2Label = new JLabel(数学成绩);JLabel score3Label = new JLabel(专业成绩);/* * 姓名文本框 */JTextField nameTextField = new JTextField(15);/* * 成绩文本框 */JTextField scoreTextField = new JTextField(15);JTextField score1TextField = new JTextField(15);JTextField score2TextField = new JTextField(15);JTextField score3TextField = new JTextField(15);/* * 输入面板 */JPanel inputPanel = new JPanel();/* * 添加按钮 */JButton insertBtn = new JButton(新建);/* * 管理面板 */JPanel managePanel = new JPanel();/* * 按钮监听器 */ButtonActionListener btnAction = new ButtonActionListener();/* * 构造器:初始化窗体 */public Create() this.setSize(280, 300);this.setLocation(300, 300);this.setResizable(false);this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);this.setTitle(java学生成绩管理系统);/* * 将窗体划分为上中下三个块 */this.setLayout(new BorderLayout();this.add(titlePanel, North);this.add(inputPanel, Center);this.add(managePanel, South);/* * 第一块用来放标题面板 = = */titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 10);titlePanel.add(titleLabel);titleLabel.setFont(new Font(黑体, Font.PLAIN, 16);/* * 第二块放输入面板 */inputPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 10);inputPanel.add(nameLabel);/ 姓名inputPanel.add(nameTextField);inputPanel.add(scoreLabel);/ 成绩inputPanel.add(scoreTextField);/ ?inputPanel.add(score1Label);/ 成绩1inputPanel.add(score1TextField);/ ?inputPanel.add(score2Label);/ 成绩2inputPanel.add(score2TextField);/ ?inputPanel.add(score3Label);/ 成绩3inputPanel.add(score3TextField);/ ?/* * 第三块是管理面板 */managePanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 10);managePanel.add(insertBtn);/* * 为按钮注册按钮监听器 */insertBtn.addActionListener(btnAction);/* * 显示窗体 */this.setVisible(true);/* * 按钮监听类 */class ButtonActionListener implements ActionListener public void actionPerformed(ActionEvent e) /* * 检查是否输入了姓名 */String name = nameTextField.getText().trim();if (name.length() = 0) JOptionPane.showMessageDialog(currentContainer, 输入的姓名为空!,操作失败, JOptionPane.ERROR_MESSAGE);return;/* * 是否要求查询 */int score = 0;int score1 = 0;int score2 = 0;int score3 = 0;/* * 检查是否输入了成绩,输入不同的成绩 */try score = Integer.parseInt(scoreTextField.getText().trim(); catch (Exception e1) JOptionPane.showMessageDialog(currentContainer, 输入的成绩不是数字!,操作失败, JOptionPane.ERROR_MESSAGE);return;try score1 = Integer.parseInt(score1TextField.getText().trim(); catch (Exception e1) JOptionPane.showMessageDialog(currentContainer, 输入的成绩不是数字!,操作失败, JOptionPane.ERROR_MESSAGE);return;try score2 = Integer.parseInt(score2TextField.getText().trim(); catch (Exception e1) JOptionPane.showMessageDialog(currentContainer, 输入的成绩不是数字!,操作失败, JOptionPane.ERROR_MESSAGE);return;try score3 = Integer.parseInt(score3TextField.getText().trim(); catch (Exception e1) JOptionPane.showMessageDialog(currentContainer, 输入的成绩不是数字!,操作失败, JOptionPane.ERROR_MESSAGE);return;/* * 是否要求录入 */if (e.getSource() = insertBtn) boolean flag = insert(name, score, score1, score2, score3); / 执行方法,进行录入操作if (flag) JOptionPane.showMessageDialog(currentContainer, 录入成功!);scoreTextField.setText(); / 清空成绩框score1TextField.setText();score2TextField.setText();score3TextField.setText(); else JOptionPane.showMessageDialog(currentContainer,录入过程中出现了异常,请联络技术人员!, 录入失败,JOptionPane.ERROR_MESSAGE);return;/* * 插入新记录 * * param name * 姓名 * param score * 成绩 */public boolean insert(String name, int score, int score1, int score2,int score3) try /* * 写入文件 */Writer out = new FileWriter(fileName, true);out.write(name + : + score + : + score1 + : + score2 + :+ score3 + rn);out.close();return true; catch (IOException e) e.printStackTrace();return false;/* * 入口方法 * * param argspublic static void main(String args) new Create();3,修改类public class Modify extends JFrame /* * 当前容器 */Container currentContainer = this;/* * 存储的文件名 */String fileName = new String(data.txt);/* * 显示标题文本 */JLabel titleLabel = new JLabel(修改成绩界面);/* * 标题面板 */JPanel titlePanel = new JPanel();/* * 显示姓名文本 */JLabel nameLabel = new JLabel(学生姓名);/* * 显示成绩文本 */JLabel scoreLabel = new JLabel(学生学号);JLabel score1Label = new JLabel(英语成绩);JLabel score2Label = new JLabel(数学成绩);JLabel score3Label = new JLabel(专业成绩);/* * 姓名文本框 */JTextField nameTextField = new JTextField(15);/* * 成绩文本框 */JTextField scoreTextField = new JTextField(15);JTextField score1TextField = new JTextField(15);JTextField score2TextField = new JTextField(15);JTextField score3TextField = new JTextField(15);/* * 输入面板 */JPanel inputPanel = new JPanel();/* * 修改按钮 */JButton modifyBtn = new JButton(修改);/* * 管理面板 */JPanel managePanel = new JPanel();/* * 按钮监听器 */ButtonActionListener btnAction = new ButtonActionListener();/* * 构造器:初始化窗体 */public Modify() this.setSize(280, 300);this.setLocation(300, 300);this.setResizable(false);this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);this.setTitle(java学生成绩管理系统);/* * 将窗体划分为上中下三个块 */this.setLayout(new BorderLayout();this.add(titlePanel, North);this.add(inputPanel, Center);this.add(managePanel, South);/* * 第一块用来放标题面板 = = */titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 10);titlePanel.add(titleLabel);titleLabel.setFont(new Font(黑体, Font.PLAIN, 16);/* * 第二块放输入面板 */inputPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 10);inputPanel.add(nameLabel);/ 姓名inputPanel.add(nameTextField);inputPanel.add(scoreLabel);/ 成绩inputPanel.add(scoreTextField);/ inputPanel.add(score1Label);/ 成绩1inputPanel.add(score1TextField);/ inputPanel.add(score2Label);/ 成绩2inputPanel.add(score2TextField);/ inputPanel.add(score3Label);/ 成绩3inputPanel.add(score3TextField);/* 第三块是管理面板 */managePanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 10);managePanel.add(modifyBtn);/* * 为按钮注册按钮监听器 */modifyBtn.addActionListener(btnAction);/* * 显示窗体 */this.setVisible(true);/* * 按钮监听类 */class ButtonActionListener implements ActionListener public void actionPerformed(ActionEvent e) /* * 检查是否输入了姓名 */String name = nameTextField.getText().trim();if (name.length() = 0) JOptionPane.showMessageDialog(currentContainer, 输入的姓名为空!,操作失败, JOptionPane.ERROR_MESSAGE);return;/* * 是否要求查询 */int score = 0;int score1 = 0;int score2 = 0;int score3 = 0;/* * 检查是否输入了成绩,输入不同的成绩 */try score = Integer.parseInt(scoreTextField.getText().trim(); catch (Exception e1) JOptionPane.showMessageDialog(currentContainer, 输入的成绩不是数字!,操作失败, JOptionPane.ERROR_MESSAGE);return;try score1 = Integer.parseInt(score1TextField.getText().trim(); catch (Exception e1) JOptionPane.showMessageDialog(currentContainer, 输入的成绩不是数字!,操作失败, JOptionPane.ERROR_MESSAGE);return;try score2 = Integer.parseInt(score2TextField.getText().trim(); catch (Exception e1) JOptionPane.showMessageDialog(currentContainer, 输入的成绩不是数字!,操作失败, JOptionPane.ERROR_MESSAGE);return;try score3 = Integer.parseInt(score3TextField.getText().trim(); catch (Exception e1) JOptionPane.showMessageDialog(currentContainer, 输入的成绩不是数字!,操作失败, JOptionPane.ERROR_MESSAGE);return;/* * 是否要求录入 */* * 是否要求修改 */if (e.getSource() = modifyBtn) int choose = JOptionPane.showConfirmDialog(currentContainer,确定要修改该学生的成绩吗?, 确认修改,JOptionPane.YES_NO_CANCEL_OPTION);if (choose = JOptionPane.YES_OPTION) boolean flag = modify(name, score, score1, score2, score3); / 当确定时修改所有名字为name的同学的成绩为scoreif (flag) JOptionPane.showMessageDialog(currentContainer, 已将修改,修改成功!, JOptionPane.PLAIN_MESSAGE); else JOptionPane.showMessageDialog(currentContainer,没有该姓名的同学的成绩记录!, 修改失败!,JOptionPane.ERROR_MESSAGE);return;public boolean modify(String name, int score, int score1, int score2,int score3) try /* * 先读入所有学生成绩信息, 把满足条件的记录更新为新成绩后,暂存到内存中 其他记录直接存储 */BufferedReader in = new BufferedReader(new FileReader(fileName);String line = null, data = ;boolean flag = false;while (line = in.readLine() != null) String info = line.split(:);if (info0.equals(name) line = info0 + : + score + : + score1 + : + score2+ : + score3;flag = true;data += line + rn;in.close();/* * 重新写文件 */Writer out = new FileWriter(fileName);out.write(data);out.close();return flag; catch (IOException e) e.printStackTrace();return false;入口方法public static void main(String args) new Modify();4,删除类public class Delete extends JFrame Container currentContainer = this;String fileName = new String(data.txt);JLabel titleLabel = new JLabel(刪除成绩界面);JPanel titlePanel = new JPanel();JLabel nameLabel = new JLabel(学生姓名);JLabel scoreLabel = new JLabel(学生学号);JLabel score1Label = new JLabel(英语成绩);JLabel score2Label = new JLabel(数学成绩);JLabel score3Label = new JLabel(专业成绩);JTextField nameTextField = new JTextField(15);JTextField scoreTextField = new JTextField(15);JTextField score1TextField = new JTextField(15);JTextField score2TextField = new JTextField(15);JTextField score3TextField = new JTextField(15);JPanel inputPanel = new JPanel();JButton deleteBtn = new JButton(删除);JPanel managePanel = new JPanel();ButtonActionListener btnAction = new ButtonActionListener();public Delete() this.setSize(280, 300);this.setLocation(300, 300);this.setResizable(false);this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);this.setTitle(java学生成绩管理系统);this.setLayout(new BorderLayout();this.add(titlePanel, North);this.add(inputPanel, Center);this.add(managePanel, South);titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 10);titlePanel.add(titleLabel);titleLabel.setFont(new Font(黑体, Font.PLAIN, 16);inputPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 10);inputPanel.add(nameLabel);/ 姓名inputPanel.add(nameTextField);inputPanel.add(scoreLabel);/ 成绩inputPanel.add(scoreTextField);/ ?inputPanel.add(score1Label);/ 成绩1inputPanel.add(score1TextField);/ ?inputPanel.add(score2Label);/ 成绩2inputPanel.add(score2TextField);/ ?inputPanel.add(score3Label);/ 成绩3inputPanel.add(score3TextField);/ ?managePanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 10);managePanel.add(deleteBtn);deleteBtn.addActionListener(btnAction);this.setVisible(true);class ButtonActionListener implements ActionListener public void actionPerformed(ActionEvent e) String name = nameTextField.getText().trim();if (name.length() = 0) JOptionPane.showMessageDialog(currentContainer, 输入的姓名为空!,操作失败, JOptionPane.ERROR_MESSAGE);return;int score = 0;int score1 = 0;int score2 = 0;int score3 = 0;if (e.getSource() = deleteBtn) try score = Integer.parseInt(scoreTextField.getText().trim();int choose = JOptionPane.showConfirmDialog(currentContainer, 确定要删除该学号的同学吗?, 确认删除,JOptionPane.YES_NO_CANCEL_OPTION);if (choose = JOptionPane.YES_OPTION) boolean flag = delete(name, score); / 当确定时删除名字为name的同学成绩为score的成绩一次if (flag) nameTextField.setText(); / 清空姓名框scoreTextField.setText();score1TextField.setText();score2TextField.setText();score3TextField.setText();/ 清空成绩框JOptionPane.showMessageDialog(currentContainer,已删除该同学的成绩!, 删除成功!,JOptionPane.PLAIN_MESSAGE); else JOptionPane.showMessageDialog(currentContainer,沒有找到改学号的同学!, 删除失败!,JOptionPane.PLAIN_MESSAGE); catch (NumberFormatException e1) / 当catch到NumberFormatException时说明parseInt失败:没有输入成绩,此时应删除所有成绩int choose = JOptionPane.showConfirmDialog(currentContainer, 确定要删除所有重名的同学吗?, 确认删除,JOptionPane.YES_NO_CANCEL_OPTION);if (choose = JOptionPane.YES_OPTION) boolean flag = delete(name); / 当确定时删除名字为name的同学的所有成绩if (flag) nameTextField.setText(); / 清空姓名框scoreTextField.setText(); / 清空成绩框JOptionPane.showMessageDialog(currentContainer,已删除该同学的所有成绩!, 删除成功!,JOptionPane.PLAIN_MESSAGE); else JOptionPane.showMessageDialog(currentContainer,该同学没有成绩!, 删除失败!,JOptionPane.PLAIN_MESSAGE);return;try score = Integer.parseInt(scoreTextField.getText().trim(); catch (Exception e1) JOptionPane.showMessageDialog(currentContainer, 输入的成绩不是数字!,操作失败, JOptionPane.ERROR_MESSAGE);return;try score1 = Integer.parseInt(score1TextField.getText().trim(); catch (Exception e1) JOptionPane.showMessageDialog(currentContainer, 输入的成绩不是数字!,操作失败, JOptionPane.ERROR_MESSAGE);return;try score2 = Integer.parseInt(score2TextField.getText().trim(); catch (Exception e1) JOptionPane.showMessageDialog(currentContainer, 输入的成绩不是数字!,操作失败, JOptionPane.ERROR_MESSAGE);return;try score3 = Integer.parseInt(score3TextField.getText().tri
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸下载 > 其他图纸


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!