学生成绩管理系统(Java)

目录

 

 

 ​编辑

需求分析:

登录界面(LoginPanel)

主界面(MainApp)

重写

1.班级重写(cs.practics.bean.BjBean.java)

2.课程重写(cs.practics.bean.CourseBean.java)

3.成绩重写(cs.practics.bean.MarkBean.java)

4.学生重写(cs.practics.bean.StudentBean.java)

班级管理

1.班级增加(cs.practics.bj.BJAddPanel)

2.班级查询(cs.practics.bj.BjFindPanel)

3.班级服务(cs.practics.service.BjService.java)

4.成绩添加(MarkInputPanel.java)

5.班级查询(MarkSelectPanel.java)

6.学生添加(StudentAddPanel.java)

7.学生查询(StudentSelectPanel.java)

课程管理

1.课程添加(cs.practics.course.CouresAddPanel.java)

2.课程查询(cs.practics.course.CouresSelectPanel.java)

服务

1.班级服务(cs.practics.service.BjService.java)

2.课程服务(cs.practics.service.CourseService.java)

3.成绩服务(cs.practics.service.MarkService.java)

4.学生服务(cs.practics.service.StudentService.java)

5.工具类(cs.practics.service.FileUtil.java)


 

 

需求分析:

1. 产品介绍

本学生成绩管理系统模块是为了实现学校人力资源的优化和学生成绩管理的科学管理而设计的,通过试用本系统,可以更加有效的管理学生成绩信息,其中包括学生的基本信息,成绩信息并且具有信息的增加,查询,修改等功能。

2. 产品面向的用户群体

本系统主要面向教师和学生。

(1)教师:登录管理、用户管理、成绩管理等。

(2)学生:主要使用的业务模块包括系统登录、查询成绩。

 

3. 产品应当遵循的标准或规范

(1)专业编号遵循国家统计规范

(2)数据库的设计遵循本项目要求的统一设计规范。

4. 产品的范围

本项目主要分为成绩管理、成绩查询设计管理、登录管理、学生管理。

5. 产品中的角色

角色名称

职责描述

教师

管理系统中的基础数据以及系统设置

学生

登陆系统之后,以及查看自己的成绩

6. 产品的功能需求

6.1 功能性需求分类

 

 

功能类别

功能名称

描述

登录功能

学生登录

学生用户登录信息

教师登录

教师用户登录信息

班级管理

查询

查询班级信息

新增

新增班级信息

修改

修改班级信息

删除

删除班级信息

学生管理

查询

查询学生信息

新增

新增学生信息

修改

修改学生信息

删除

删除学生信息

成绩管理

成绩查询

查询学生的成绩信息

成绩录入

录入学生的成绩

成绩管理

修改学生的成绩

成绩查询统计

查询课程成绩及平均分

按班级分组查询课程及平均分

学生成绩查询

查询成绩

学生登录账户查询自己的每门成绩

6.2功能层次结构图

2f7273cdfad8975a8955c25f0bb16071.gif

正在上传…重新上传取消

                                

 

7. 产品的非功能性需求

7.1 用户界面需求

需求名称

详细要求

整体风格

以蓝色为主色调

兼容性

能在主流浏览器(火狐、谷歌、IE8+、360浏览器)上运行

 

 

 

 

 

 

 

 

7.2 软硬件环境需求

需求名称

详细要求

开发语言

Java或.NET

运行环境

Jdk1.6+或.NET Framework 3.5以上

数据库

Mysql5.0或者SqlServer 2005以上

操作系统

Windows Server2008

 

 

 

 

7.3 产品质量需求

主要质量属性

详细要求

正确性

无数据计算错误,无流程错误

健壮性

程序出错后,系统能正常捕获异常,不会导致程序终止运行

可靠性

系统支持7*24无间断运行,不会因系统功能的复杂运算而导致系统崩溃

性能、效率

数据请求在0.2S内返回

易用性

功能使用,操作简单,避免繁琐的逻辑设定

清晰性

功能结果及名称清晰,避免用户误解

安全性

用户必须成功登陆后,根据权限才可使用对应的功能

可扩展性

提供良好的系统接口,支持后续功能的开发扩展

兼容性

兼容主流浏览器(火狐、谷歌、IE8+、360浏览器)

可移植性

能较好部署到其他版本的Windows操作系统上

 

 

8. 其它需求

下面开始代码的分布以及书写

登录界面(LoginPanel)

package cs.practics;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public class LoginPanel extends JPanel {
	    private JTextField txtUserName;
	    private JTextField txtPwd;
	    private JButton btnOk;
	    private JButton btnQuit;

	    @SuppressWarnings("unused")
		private MainApp parent;

	    public LoginPanel(MainApp parent){
	        this.parent = parent;

	        setLayout(null);
	        JLabel jLabel = new JLabel("用户名:");
	        jLabel.setBounds(500, 200, 70, 30);
	        add(jLabel);
	        txtUserName = new JTextField();
	        txtUserName.setBounds(570, 200, 200, 30);
	        add(txtUserName);

	        JLabel jLabel2 = new JLabel("密码:");
	        jLabel2.setBounds(500, 250, 70, 30);
	        add(jLabel2);
	        txtPwd = new JTextField();
	        txtPwd.setBounds(570, 250, 200, 30);
	        add(txtPwd);

	        btnOk= new JButton("确定");
	        btnOk.setBounds(580, 300, 80, 30);
	        add(btnOk);
	        btnOk.addActionListener(new ActionListener() {

	            @Override
	            public void actionPerformed(ActionEvent e) {
	                if (txtUserName.getText().isEmpty()) {
	                    JOptionPane.showMessageDialog(null, "用户名不能为空", "错误", JOptionPane.ERROR_MESSAGE);
	                    return ;
	                }
	                if (txtPwd.getText().isEmpty()) {
	                    JOptionPane.showMessageDialog(null, "密码不能为空", "错误", JOptionPane.ERROR_MESSAGE);
	                    return ;
	                }
	                if (txtUserName.getText().equals("1") && txtPwd.getText().equals("1")){
	                    JOptionPane.showMessageDialog(null, "登录成功!");
	                    parent.loginSuccess();
	                }else{
	                    JOptionPane.showMessageDialog(null, "失败成功!");
	                }

	            }
	        });

	        btnQuit = new JButton("退出");
	        btnQuit.setBounds(680, 300, 80, 30);
	        add(btnQuit);
	        btnQuit.addActionListener(new ActionListener() {
	            @Override
	            public void actionPerformed(ActionEvent e) {
	                parent.quit();
	            }
	        });

	    }
	}

主界面(MainApp)

​
package cs.practics;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

import cs.practics.bj.BJAddPanel;

import cs.practics.bj.BjFindPanel;
import cs.practics.bj.MarkInputPanel;
import cs.practics.bj.MarkSelectPanel;
import cs.practics.bj.StudentAddPanel;
import cs.practics.bj.StudentSelectPanel;
import cs.practics.course.CourseAddPanel;
import cs.practics.course.CourseSelectPanel;

@SuppressWarnings("serial")
public class MainApp extends JFrame implements ActionListener {

	    @SuppressWarnings("unused")
		private static final long seriaLVersionUID = -2550337629393921238L;

	    private JMenuBar menuBar;
	    private JMenu courseMenu;
	    private JMenu bjMenu;
	    private JMenu markMenu;
	    private JMenu studentMenu;

	    @SuppressWarnings("unused")
		private JMenuItem[] courseMenuItems;
	    @SuppressWarnings("unused")
		private JMenuItem[] bjMenuItems;
	    @SuppressWarnings("unused")
		private JMenuItem[] markMenuItems;
	    @SuppressWarnings("unused")
		private JMenuItem[] studentMenuItems;

	    private JPanel curPanel = null;
	    public MainApp() {
	        setTitle("学生成绩管理系统");
	        curPanel = new LoginPanel(this);
	        getContentPane().add(curPanel, BorderLayout.CENTER);
	        setSize(1600, 900);
	        setLocationRelativeTo(null);
	        setVisible(true);
	        initMenu();
	        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	    }

	    private void initMenu() {
	        menuBar = new JMenuBar();
	        this.setJMenuBar(menuBar);
	        menuBar.setVisible(false);
	        bjMenu = new JMenu("班级管理");
	        String[] op = { "新增班级", "查询班级"};
	        initMenuItem(bjMenu, op);
	        menuBar.add(bjMenu);

	        courseMenu = new JMenu("课程管理");
	        op = new String[]{ "新增课程", "查询课程"};
	        initMenuItem(courseMenu, op);
	        menuBar.add(courseMenu);

	        studentMenu = new JMenu("学生管理");
	        op = new String[]{ "新增学生", "学生查询"};
	        initMenuItem(studentMenu, op);
	        menuBar.add(studentMenu);

	        markMenu = new JMenu("成绩管理");
	        op = new String[]{ "成绩查询", "录入成绩"};
	        initMenuItem(markMenu, op);
	        menuBar.add(markMenu);
	    }

	    private void initMenuItem(JMenu menu, String[] opers) {
	        JMenuItem[] menuItems = new JMenuItem[opers.length];
	        for (int i = 0; i < opers.length; i++) {
	            menuItems[i] = new JMenuItem(opers[i]);
	            menuItems[i].addActionListener(this);
	            menuItems[i].setActionCommand(menu.getActionCommand() + "-" + opers[i]);
	            menu.add(menuItems[i]);
	        }
	    }
	    @Override
	    public void actionPerformed(ActionEvent e) {
	        removePanel();
	        if ("课程管理-新增课程".equals(e.getActionCommand())){
	            curPanel = new CourseAddPanel(this);
	            getContentPane().add(curPanel, BorderLayout.CENTER);
	            refresh();
	        } else if ("班级管理-新增班级".equals(e.getActionCommand())){
	            curPanel = new BJAddPanel(this);
	            getContentPane().add(curPanel, BorderLayout.CENTER);
	            refresh();
	        }else if ("班级管理-查询班级".equals(e.getActionCommand())){
	            curPanel = new BjFindPanel(this);
	            getContentPane().add(curPanel, BorderLayout.CENTER);
	            refresh();
	        }
	        /*else if ("班级管理-修改班级".equals(e.getActionCommand())){
	            curPanel = new BjDeletePanel(this);
	            getContentPane().add(curPanel, BorderLayout.CENTER);
	            refresh();
	        }*/else if ("课程管理-查询课程".equals(e.getActionCommand())){
	            curPanel = new CourseSelectPanel(this);
	            getContentPane().add(curPanel, BorderLayout.CENTER);
	            refresh();
	        }else if ("学生管理-新增学生".equals(e.getActionCommand())){
	            curPanel = new StudentAddPanel(this);
	            getContentPane().add(curPanel, BorderLayout.CENTER);
	            refresh();
	        }else if ("学生管理-学生查询".equals(e.getActionCommand())){
	            curPanel = new StudentSelectPanel(this);
	            getContentPane().add(curPanel, BorderLayout.CENTER);
	            refresh();
	        }else if ("成绩管理-录入成绩".equals(e.getActionCommand())){
	            curPanel = new MarkInputPanel(this);
	            
	            getContentPane().add(curPanel, BorderLayout.CENTER);
	            refresh();
	        }else if ("成绩管理-成绩查询".equals(e.getActionCommand())){
	            curPanel = new MarkSelectPanel(this);
	            getContentPane().add(curPanel, BorderLayout.CENTER);
	            refresh();
	        }
	        
	    }
	    public void removePanel() {
	        if (curPanel != null) {
	            remove(curPanel);
	        }
	        curPanel = null;
	    }
	    public void refresh(){
	        getContentPane().validate();
	        getContentPane().repaint();
	    }

	    public void loginSuccess(){
	        menuBar.setVisible(true);
	        removePanel();
	        refresh();
	    }
	    public void quit(){
	        System.exit(0);
	    }
	    public static void main(String[] args) {
	        new MainApp();
	    }

	}

​

重写

1.班级重写(cs.practics.bean.BjBean.java)

package cs.practics.bean;

import java.io.Serializable;

@SuppressWarnings("serial")
public class BjBean implements Serializable {
	private String BjID;
    private String Bjname;
    
    public String getBjID() {
        return BjID;
    }

    public void setBjID(String bjID) {
        BjID = bjID;
    }

    public String getBjname() {
        return Bjname;
    }

    public void setBjname(String bjname) {
        Bjname = bjname;
    }
    public String toString() {
    	return Bjname;
    }

	public String getBjName() {
		// TODO Auto-generated method stub
		return Bjname;
	}
	

}

2.课程重写(cs.practics.bean.CourseBean.java)

package cs.practics.bean;

import java.io.Serializable;

@SuppressWarnings("serial")
public class CourseBean implements Serializable{
	private String courseID;
    private String courseName;

    public String getCourseID() {
        return courseID;
    }

    public void setCourseID(String courseID) {
        this.courseID = courseID;
    }

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }
    public String toString(){
    	return this.courseName;
    }

}

3.成绩重写(cs.practics.bean.MarkBean.java)

package cs.practics.bean;

import java.io.Serializable;
import java.math.BigDecimal;

public class MarkBean implements Serializable{
	private static final long serialVersionUID = -6391917037783889667L;
	private String studentID;
	private String studentName;
	private String courseID;
	private String courseName;
	private String bjID;
	private String bjName;
	private BigDecimal mark;
	
	
	public String getStuName() {
		return studentName;
	}
	public void setStudentName(String studentName) {
		this.studentName = studentName;
	}
	public String getCourseName() {
		return courseName;
	}
	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}
	public String getBjID() {
		return bjID;
	}
	public void setBjID(String bjID) {
		this.bjID = bjID;
	}
	public String getBjName() {
		return bjName;
	}
	public void setBjName(String bjName) {
		this.bjName = bjName;
	}
	public String getStudentID() {
		return studentID;
	}
	public void setStudentID(String studentID) {
		this.studentID = studentID;
	}
	public String getCourseID() {
		return courseID;
	}
	public void setCourseID(String courseID) {
		this.courseID = courseID;
	}
	public BigDecimal getMark() {
		return mark;
	}
	public void setMark(BigDecimal mark) {
		this.mark = mark;
	}
	public Object getStudentName() {
		// TODO Auto-generated method stub
		return studentName;
	}

}

4.学生重写(cs.practics.bean.StudentBean.java)

package cs.practics.bean;

import java.io.Serializable;
import java.math.BigDecimal;

public class MarkBean implements Serializable{
	private static final long serialVersionUID = -6391917037783889667L;
	private String studentID;
	private String studentName;
	private String courseID;
	private String courseName;
	private String bjID;
	private String bjName;
	private BigDecimal mark;
	
	
	public String getStuName() {
		return studentName;
	}
	public void setStudentName(String studentName) {
		this.studentName = studentName;
	}
	public String getCourseName() {
		return courseName;
	}
	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}
	public String getBjID() {
		return bjID;
	}
	public void setBjID(String bjID) {
		this.bjID = bjID;
	}
	public String getBjName() {
		return bjName;
	}
	public void setBjName(String bjName) {
		this.bjName = bjName;
	}
	public String getStudentID() {
		return studentID;
	}
	public void setStudentID(String studentID) {
		this.studentID = studentID;
	}
	public String getCourseID() {
		return courseID;
	}
	public void setCourseID(String courseID) {
		this.courseID = courseID;
	}
	public BigDecimal getMark() {
		return mark;
	}
	public void setMark(BigDecimal mark) {
		this.mark = mark;
	}
	public Object getStudentName() {
		// TODO Auto-generated method stub
		return studentName;
	}

}

班级管理

1.班级增加(cs.practics.bj.BJAddPanel)

package cs.practics.bj;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import cs.practics.bean.BjBean;
import cs.practics.service.BjService;

@SuppressWarnings({ "serial", "unused" })
public class BJAddPanel extends JPanel {
    private JTextField txtID;
    private JTextField txtName;
    private JButton btnOk;
    private JButton btnCancel;
    private JFrame parent;
    public BJAddPanel (JFrame parent) {
        this.parent = parent;
        setLayout(null);
        JLabel jLabel = new JLabel("班级ID:");
        jLabel.setBounds(500, 200, 70, 30);
        add(jLabel);
        txtID = new JTextField();
        txtID.setBounds(570, 200, 200, 30);
        add(txtID);
        JLabel jLabel2 = new JLabel("班级名称:");
        jLabel2.setBounds(500, 250, 70, 30);
        add(jLabel2);
        txtName = new JTextField();
        txtName.setBounds(570, 250, 200, 30);
        add(txtName);
        btnOk = new JButton("确定");
        btnOk.setBounds(520, 300, 80, 30);
        add(btnOk);
        btnOk.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
            	
                if (txtID.getText().isEmpty()) {
                    JOptionPane.showMessageDialog(null, "班级ID不能为空", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if (txtName.getText().isEmpty()) {
                    JOptionPane.showMessageDialog(null, "班级名称不能为空", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                BjBean BjBean = new BjBean();
                BjBean.setBjID(txtID.getText());
                BjBean.setBjname(txtName.getText());
                Integer rtn = BjService.bjService.add(BjBean);
                if (rtn != 1) {
                    JOptionPane.showMessageDialog(null, txtID.getText() + "." + txtName.getText() + "添加失败,班级ID已经存在", "错误", JOptionPane.ERROR_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(null, "添加成功!");
                    txtID.setText("");
                    txtName.setText("");
                }

            }
        });
        btnCancel = new JButton("取消");
        btnCancel.setBounds(680,300,80,30);
        add(btnCancel);
        btnCancel.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cancel();
            }
        });
    }
    protected void cancel(){
        parent.remove(this);
        parent.validate();
        parent.repaint();
    }
}

2.班级查询(cs.practics.bj.BjFindPanel)

package cs.practics.bj;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import cs.practics.bean.BjBean;
import cs.practics.service.BjService;



public class BjFindPanel extends JPanel {
	private static final long serialVersionUID=3254423774866407987L;
	private JTextField txtID;
	private JTextField txtSelID;
    private JTextField txtName;
    //private JTextField txtBjName;
    private JButton btnOk;
    private JButton btnCancel;
    private JFrame parent;
    
    public BjFindPanel  (JFrame parent) {
        this.parent = parent;
        setLayout(null);
        JLabel jLabel = new JLabel("查询班级的ID:");
        jLabel.setBounds(500, 200, 70, 30);
        add(jLabel);
        txtSelID = new JTextField();
        txtSelID.setBounds(570, 200, 200, 30);
        add(txtSelID);
        
        JLabel jLabel1 = new JLabel("班级ID:");
        jLabel1.setBounds(500, 250, 70, 30);
        add(jLabel1);
        txtID = new JTextField();
        txtID.setBounds(570, 250, 200, 30);
        add(txtID);
        txtID.setEditable(false);
        
        JLabel jLabel21 = new JLabel("班级名:");
        jLabel21.setBounds(500, 300, 70, 30);
        add(jLabel21);
        txtName = new JTextField();
        txtName.setBounds(570, 300, 200, 30);
        add(txtName);
        txtName.setEditable(false);
        
        btnOk = new JButton("确定");
        btnOk.setBounds(520, 350, 80, 30);
        add(btnOk);
        btnOk.addActionListener(new ActionListener() {
            @SuppressWarnings("unused")
			@Override
            public void actionPerformed(ActionEvent e) {
            	/*BjBean bjBean = (BjBean )jComboBox.getSelectedItem();
            	System.out.println(bjBean.getBjID()+","+bjBean.getBjname());*/
                if (txtSelID.getText().isEmpty()) {
                    JOptionPane.showMessageDialog(null, "班级ID不能为空", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                
                BjBean BjBean = new BjBean();
                BjBean.setBjID(txtSelID.getText());
                
                BjBean rtn = BjService.bjService.select(BjBean);
                if (rtn == null) {
                    JOptionPane.showMessageDialog(null, "查询失败,班级ID不存在", "错误", JOptionPane.ERROR_MESSAGE);
                    txtSelID.setText("");
                    txtID.setText("");
                    txtName.setText("");
                } else {
                    
                    txtID.setText(rtn.getBjID());
                    txtName.setText(rtn.getBjName());
                    //txtBjName.setText(rtn.getBjName());
                    txtSelID.setText("");
                }

            }
        });
        btnCancel = new JButton("取消");
        btnCancel.setBounds(680,350,80,30);
        add(btnCancel);
        btnCancel.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cancel();
            }
        });
    }
    protected void cancel(){
        parent.remove(this);
        parent.validate();
        parent.repaint();
    }

}

3.班级服务(cs.practics.service.BjService.java)

package cs.practics.service;

import java.beans.beancontext.BeanContext;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import cs.practics.bean.BjBean;
import cs.practics.bean.StudentBean;

public class BjService {
	 public static final String dz1 = "E:/java实训/bj/data/data.data";
	    private List<BjBean> list = null;
	    public static BjService bjService = new BjService();
	    private  BjService(){
	        try{
	            list = FileUtil.loadData(dz1);
	        }catch (ClassNotFoundException| IOException e){
	            e.printStackTrace();
	        }
	        if(list==null)list = new ArrayList<>();
	    }
	    public BjBean searchByBjID(String bjID){
	        for(BjBean bjBean:list){
	            if(bjBean.getBjID().equals(bjID)) return bjBean;
	        }
	        return null;
	    }
	    public int add(BjBean bean){
	        try {
	        	BjBean tmp = searchByBjID(bean.getBjID());
	            if (tmp !=null) return -2;
	            list.add(bean);
	            FileUtil.writeData(list,dz1);
	            return 1;
	        }catch (Exception e){
	            e.printStackTrace();
	            return -1;
	        }
	    }
		public List<BjBean> list() {
			// TODO Auto-generated method stub
			return list;
		}
		public Integer add(StudentBean studentBean) {
			// TODO Auto-generated method stub
			return add(studentBean);
		}
		public BjBean select(BjBean bjBean) {
			// TODO Auto-generated method stub
			BjBean rtn = searchByBjID(bjBean.getBjID());
			if(rtn != null) {
				return rtn;
			}else {
				return null;
			}
		}
}

4.成绩添加(MarkInputPanel.java)

package cs.practics.bj;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import cs.practics.bean.BjBean;
import cs.practics.bean.CourseBean;
import cs.practics.bean.MarkBean;
import cs.practics.service.BjService;
import cs.practics.service.CourseService;
import cs.practics.service.MarkService;

public class MarkInputPanel extends JPanel {
private static final long serialVersionUID = 3254423774866407987L;

protected static final String bjBean = null;
	
	private JButton btnOK;
	private JButton btnCancel;
	private JButton btnSubmit;
	private JFrame parent;
	private JComboBox<BjBean> jComboBox;
	private JComboBox<CourseBean> jComboBox2;
	private JTable jTable;
	private JScrollPane jScrollPane=null;

	
	public MarkInputPanel(JFrame parent) {
		this.parent = parent;
		setLayout(null);
//		setLayout(new BorderLayout());
		
		
		JLabel jbl2 = new JLabel("班级:");
		jbl2.setBounds(180, 10, 70, 30);
		add(jbl2);
		List<BjBean> classes = BjService.bjService.list();
		if (classes != null) {
			BjBean[] arr = classes.toArray(new BjBean[0]);
			jComboBox = new JComboBox<>(arr);
		}else {
			jComboBox = new JComboBox<>();
		}
		
		jComboBox.setBounds(250, 10, 200, 30);
		add(jComboBox);

		JLabel jbl3 = new JLabel("课程:");
		jbl3.setBounds(480, 10, 70, 30);
		add(jbl3);
		List<CourseBean> courses = CourseService.courseService.list();
		if (courses != null) {
			CourseBean[] arr = courses.toArray(new CourseBean[0]);
			jComboBox2 = new JComboBox<>(arr);
		}else {
			jComboBox2 = new JComboBox<>();
		}
		
		jComboBox2.setBounds(550, 10, 200, 30);
		add(jComboBox2);

		btnOK = new JButton("查询");
		btnOK.setBounds(780, 10, 80, 30);
		add(btnOK);
		btnOK.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				BjBean bjBean = (BjBean) jComboBox.getSelectedItem();
				CourseBean courseBean = (CourseBean) jComboBox2.getSelectedItem();
				if (bjBean == null || courseBean == null) {
					JOptionPane.showMessageDialog(null, "没有选班级或课程", "错误", JOptionPane.ERROR_MESSAGE);
					return;
				}
				List<MarkBean> marks = MarkService.markService.search(bjBean.getBjID(), courseBean);
				if (marks != null && marks.size() != 0) {
					Object[] columnNames = { "学号", "姓名", "班级ID", "班级", "课程ID", "课程名", "成绩" };
					Object[][] rowData = new Object[marks.size()][columnNames.length];
					for (int i = 0; i < marks.size(); i++) {
						MarkBean markBean = marks.get(i);
						rowData[i] = new Object[] { markBean.getStudentID(),markBean.getStudentName(), markBean.getBjID(),
								markBean.getBjName(), markBean.getCourseID(), markBean.getCourseName(), markBean.getMark() };
					}
					DefaultTableModel model = new DefaultTableModel(rowData, columnNames) {
						private static final long serialVersionUID = -4509445279793353632L;

						public boolean isCellEditable(int rowIndex, int columnIndex) {
							if (columnIndex == 6)
								return true;
							return false;
						}

						public void setValueAt(Object value, int rowIndex, int columnIndex) {
							if (columnIndex == 6) {
								try {
									new BigDecimal("" + value);
									super.setValueAt(value, rowIndex, columnIndex);
								} catch (Exception e) {
									JOptionPane.showMessageDialog(null, "只能输入数字", "错误", JOptionPane.ERROR_MESSAGE);
								}

							}
						}
					};
					jTable = new JTable(model);
					jTable.setRowHeight(30);
					jTable.setRowMargin(5);
					jTable.setShowHorizontalLines(true);
					jTable.setShowVerticalLines(true);
					if (jScrollPane!=null){
						remove(jScrollPane);
					}
					jScrollPane = new JScrollPane(jTable);
					add(jScrollPane);
					jScrollPane.setBounds(40, 60, 1200, 500);
				}
				
			}
		});

		btnCancel = new JButton("取消");
		btnCancel.setBounds(870, 10, 80, 30);
		add(btnCancel);
		btnCancel.addActionListener(e -> cancel());

		btnSubmit = new JButton("提交");
		btnSubmit.setBounds(960, 10, 80, 30);
		add(btnSubmit);
		btnSubmit.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				List<MarkBean> marks = new ArrayList<>();

				for (int i = 0; i < jTable.getRowCount(); i++) {
					MarkBean markBean = new MarkBean();
					markBean.setStudentID(""+jTable.getValueAt(i, 0));
					markBean.setStudentName(""+jTable.getValueAt(i, 1));
					markBean.setBjID(""+jTable.getValueAt(i, 2));
					markBean.setBjName(""+jTable.getValueAt(i, 3));
					markBean.setCourseID(""+jTable.getValueAt(i, 4));
					markBean.setCourseName(""+jTable.getValueAt(i, 5));
					markBean.setMark(new BigDecimal(""+jTable.getValueAt(i,6)));
					marks.add(markBean);
				}
				MarkService.markService.sumbit(marks);
				JOptionPane.showMessageDialog(null, "提交成功!");
			}
		});
	}
	protected void cancel() {
		parent.remove(this);
		parent.validate();
		parent. Repaint();

	}


}

5.班级查询(MarkSelectPanel.java)

package cs.practics.bj;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import cs.practics.bean.MarkBean;
import cs.practics.service.MarkService;

@SuppressWarnings("serial")
public class MarkSelectPanel extends JPanel {
	    private JTextField txtID;
	    private JButton btnOk;
	    private JButton btnCancel;
	    private JFrame parent;
	    private JTable jTable;
	    private JScrollPane jScrollPane=null;
	    public MarkSelectPanel(JFrame parent){
	        this.parent = parent;
	        setLayout(null);
	        JLabel jLabel = new JLabel("学生ID:");
	        jLabel.setBounds(500,10,70,30);
	        add(jLabel);
	        txtID = new JTextField();
	        txtID.setBounds(550,10,200,30);
	        add(txtID);
	        btnOk = new JButton("查询" );
	        btnOk.setBounds(780,10,80,30);
	        add(btnOk);
	        btnOk.addActionListener(new ActionListener() {
	            @Override
	            public void actionPerformed(ActionEvent e) {
	                if(txtID.getText().isEmpty()){
	                    JOptionPane.showMessageDialog(null,"学生ID不能为空","错误",JOptionPane.ERROR_MESSAGE);
	                    return;
	                }
	                List<MarkBean> smb = MarkService.markService.searchByStuID(txtID.getText());
	                Object[] columnNames = {"学生名","课程ID", "课程名", "成绩" };
	                Object[][] rowData = new Object[smb.size()][columnNames.length];
	                if(smb.size()!=0){
	                    for (int i=0;i<smb.size();i++){
	                        MarkBean markBean = smb.get(i);
	                        rowData [i]=new Object[]{markBean.getStudentName(),markBean.getCourseID(),markBean.getCourseName(),markBean.getMark()};
	                    }
	                    DefaultTableModel model = new DefaultTableModel(rowData, columnNames) {
	                        private static final long serialVersionUID = -4509445279793353632L;
	                        public boolean isCellEditable(int rowIndex, int columnIndex) {
	                            return false;
	                        }
	                    };
	                    jTable = new JTable(model);
	                    jTable.setRowHeight(30);
	                    jTable.setRowMargin(5);
	                    jTable.setShowHorizontalLines(true);
	                    jTable.setShowVerticalLines(true);
	                    if (jScrollPane!=null){
	                        remove(jScrollPane);
	                    }
	                    jScrollPane = new JScrollPane(jTable);
	                    add(jScrollPane);
	                    jScrollPane.setBounds(200, 60, 800, 200);
	                }else {
	                    JOptionPane.showMessageDialog(null, "没有成绩记录,查询失败!", "错误", JOptionPane.ERROR_MESSAGE);
	                }
	                }
	            });
	        btnCancel = new JButton("取消");
	        btnCancel.setBounds(870, 10, 80, 30);
	        add(btnCancel);
	        btnCancel.addActionListener(e -> cancel());
	    }
	    protected void cancel() {
	        parent.remove(this);
	        parent.validate();
	        parent.repaint();

	    }
	}

6.学生添加(StudentAddPanel.java)

package cs.practics.bj;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import cs.practics.bean.BjBean;
import cs.practics.bean.StudentBean;
import cs.practics.service.BjService;
import cs.practics.service.StudentService;

public class StudentAddPanel extends JPanel {
	    
		private static final long serialVersionUID = 3254423774866407987L;
		private JTextField txtID;
	    private JTextField txtName;
	    
	    private JButton btnOk;
	    private JButton btnCancel;
	    private JFrame parent;
	    private JComboBox<BjBean> jComboBox;
	    
	    public StudentAddPanel(JFrame parent) {
	        this.parent = parent;
	        setLayout(null);
	        
	        JLabel jLabel = new JLabel("学生ID:");
	        jLabel.setBounds(500, 200, 70, 30);
	        add(jLabel);
	        txtID = new JTextField();
	        txtID.setBounds(570, 200, 200, 30);
	        add(txtID);
	        
	        JLabel jLabel2 = new JLabel("学生姓名:");
	        jLabel2.setBounds(500, 250, 70, 30);
	        add(jLabel2);
	        txtName = new JTextField();
	        txtName.setBounds(570, 250, 200, 30);
	        add(txtName);
	        
	        JLabel label1=new JLabel("学生班级:");    //创建标签
	        label1.setBounds(500,300,200,30);
	        add(label1);
	        
	        List <BjBean> classes = BjService.bjService.list();
	        if(classes != null) {
	        	BjBean[] arr = classes.toArray(new BjBean[0]);
	        	jComboBox = new JComboBox<>(arr);
	        }else {
	        	jComboBox = new JComboBox<>();
	        }
	        
	        jComboBox.setBounds(570, 300, 200, 30);
	        add(jComboBox);

	        btnOk = new JButton("确定");
	        btnOk.setBounds(520,600 , 80, 30);
	        add(btnOk);
	        btnOk.addActionListener(new ActionListener() {
	        	
	        	
	        	@Override
	            public void actionPerformed(ActionEvent e) {
	        		//下拉框
					BjBean bjBean = (BjBean)jComboBox.getSelectedItem();
	            	System.out.println(bjBean.getBjID()+","+bjBean.getBjName());
	            	
	                if (txtID.getText().isEmpty()) {
	                    JOptionPane.showMessageDialog(null, "学生ID不能为空", "错误", JOptionPane.ERROR_MESSAGE);
	                    return;
	                }
	                if (txtName.getText().isEmpty()) {
	                    JOptionPane.showMessageDialog(null, "学生姓名不能为空", "错误", JOptionPane.ERROR_MESSAGE);
	                    return;
	                }
	                
	                
	                StudentBean studentBean = new StudentBean();
	                studentBean.setStudentID(txtID.getText());
	                studentBean.setStudentName(txtName.getText());
	                BjBean bjBean1=(BjBean)jComboBox.getSelectedItem();
	                Integer rtn = StudentService.studentService.add(studentBean,bjBean1);
	                
	                if (rtn != 1) {
	                    JOptionPane.showMessageDialog(null, txtID.getText() + "." + txtName.getText() + "添加失败,班级ID已经存在", "错误", JOptionPane.ERROR_MESSAGE);
	                } else {
	                    JOptionPane.showMessageDialog(null, "添加成功!");
	                    txtID.setText("");
	                    txtName.setText("");
	                }

	            }
	        });
	        btnCancel = new JButton("取消");
	        btnCancel.setBounds(680,600,80,30);
	        add(btnCancel);
	        btnCancel.addActionListener(new ActionListener() {
	            @Override
	            public void actionPerformed(ActionEvent e) {
	                cancel();
	            }
	        });
	    }
	    protected void cancel(){
	        parent.remove(this);
	        parent.validate();
	        parent. Repaint();
	    }

	}

7.学生查询(StudentSelectPanel.java)

package cs.practics.bj;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import cs.practics.bean.CourseBean;
import cs.practics.bean.StudentBean;
import cs.practics.service.CourseService;
import cs.practics.service.StudentService;

public class StudentSelectPanel extends JPanel {
	private static final long serialVersionUID = 3254423774866407987L;
	private JTextField txtSelID;
	private JTextField txtID;
    private JTextField txtName;
    private JTextField txtBjName;
    private JButton btnOk;
    private JButton btnCancel;
    private JFrame parent;
    
    public StudentSelectPanel(JFrame parent) {
        this.parent = parent;
        setLayout(null);
        JLabel jLabel = new JLabel("查询的学生ID:");
        jLabel.setBounds(500, 200, 70, 30);
        add(jLabel);
        txtSelID = new JTextField();
        txtSelID.setBounds(570, 200, 200, 30);
        add(txtSelID);
        
        JLabel jLabel2 = new JLabel("学生ID:");
        jLabel2.setBounds(500, 250, 70, 30);
        add(jLabel2);
        txtID = new JTextField();
        txtID.setBounds(570, 250, 200, 30);
        add(txtID);
        txtID.setEditable(false);
        
        JLabel jLabel21 = new JLabel("学生名:");
        jLabel21.setBounds(500, 300, 70, 30);
        add(jLabel21);
        txtName = new JTextField();
        txtName.setBounds(570, 300, 200, 30);
        add(txtName);
        txtName.setEditable(false);
        
        JLabel jLabel211 = new JLabel("班级名:");
        jLabel211.setBounds(500, 350, 70, 30);
        add(jLabel211);
        txtBjName = new JTextField();
        txtBjName.setBounds(570, 350, 200, 30);
        add(txtBjName);
        txtBjName.setEditable(false);
        
        btnOk = new JButton("确定");
        btnOk.setBounds(520, 400, 80, 30);
        add(btnOk);
        
        btnOk.addActionListener(new ActionListener() {
            @SuppressWarnings("null")
			@Override
            public void actionPerformed(ActionEvent e) {
            	/*BjBean bjBean = (BjBean )jComboBox.getSelectedItem();
            	System.out.println(bjBean.getBjID()+","+bjBean.getBjname());*/
                if (txtSelID.getText().isEmpty()) {
                    JOptionPane.showMessageDialog(null, "学生ID不能为空", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                /*if (txtName.getText().isEmpty()) {
                    JOptionPane.showMessageDialog(null, "课程名称不能为空", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }*/
                StudentBean studentBean = new StudentBean();
                studentBean.setStudentID(txtSelID.getText());
                //StudentBean.setStudentName(txtName.getText());
                StudentBean rtn = StudentService.studentService.select(studentBean);
                if (rtn ==null) {
                    JOptionPane.showMessageDialog(null,"查询失败,学生不存在", "错误", JOptionPane.ERROR_MESSAGE);
                    txtSelID.setText("");
                    txtID.setText("");
                    txtName.setText("");
                    txtBjName.setText("");
                }
                else {
                    txtBjName.setText(rtn.getBjname());
                    txtID.setText(rtn.getStudentID());
                    txtName.setText(rtn.getStudentname());
                    txtSelID.setText("");
                }

            }
        });
        btnCancel = new JButton("取消");
        btnCancel.setBounds(680,400,80,30);
        add(btnCancel);
        btnCancel.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cancel();
            }
        });
    }
    protected void cancel(){
        parent.remove(this);
        parent.validate();
        parent. Repaint();
    }

}

课程管理

1.课程添加(cs.practics.course.CouresAddPanel.java)

package cs.practics.course;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import cs.practics.bean.CourseBean;
import cs.practics.service.CourseService;

@SuppressWarnings("serial")
public class CourseAddPanel extends JPanel {
	    private JTextField txtID;
	    private JTextField txtName;
	    private JButton btnOk;
	    private JButton btnCancel;
	    private JFrame parent;
	    public CourseAddPanel(JFrame parent){
	        this.parent = parent;
	        setLayout(null);
	        JLabel jLabel = new JLabel("课程ID:");
	        jLabel.setBounds(500,200,70,30);
	        add(jLabel);
	        txtID = new JTextField();
	        txtID.setBounds(570,200,200,30);
	        add(txtID);
	        JLabel jLabel2 = new JLabel("课程名:");
	        jLabel2.setBounds(500,250,70,30);
	        add(jLabel2);
	        txtName = new JTextField();
	        txtName.setBounds(570,250,200,30);
	        add(txtName);
	        btnOk = new JButton("确定");
	        btnOk.setBounds(520,300,80,30);
	        add(btnOk);
	        btnOk.addActionListener(new ActionListener() {
	            @Override
	            public void actionPerformed(ActionEvent e) {
	                if(txtID.getText().isEmpty()){
	                    JOptionPane.showMessageDialog(null,"课程ID不能为空","错误",JOptionPane.ERROR_MESSAGE);
	                    return;
	                }
	                if(txtName.getText().isEmpty()){
	                    JOptionPane.showMessageDialog(null,"课程名不能为空","错误",JOptionPane.ERROR_MESSAGE);
	                    return;
	                }
	                CourseBean courseBean = new CourseBean();
	                courseBean.setCourseID(txtID.getText());
	                courseBean.setCourseName(txtName.getText());
	                Integer rtn = CourseService.courseService.add(courseBean);
	                if(rtn != 1){
	                    JOptionPane.showMessageDialog(null,txtID.getText()+"."+txtName.getText()+"添加失败,课程ID已经存在","错误",JOptionPane.ERROR_MESSAGE);
	                }else {
	                    JOptionPane.showMessageDialog(null,"添加成功!");
	                    txtID.setText("");
	                    txtName.setText("");
	                }

	            }
	        });
	        btnCancel = new JButton("取消");
	        btnCancel.setBounds(680,300,80,30);
	        add(btnCancel);
	        btnCancel.addActionListener(new ActionListener() {
	            @Override
	            public void actionPerformed(ActionEvent e) {
	                cancel();
	            }
	        });
	    }
	    protected void cancel(){
	        parent.remove(this);
	        parent.validate();
	        parent. Repaint();
	    }
	}

2.课程查询(cs.practics.course.CouresSelectPanel.java)

package cs.practics.course;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import cs.practics.MainApp;
import cs.practics.bean.CourseBean;
//import cs.practics.bean.StudentBean;
import cs.practics.service.CourseService;

public class CourseSelectPanel extends JPanel {
	private static final long serialVersionUID = 3254423774866407987L;
	private JTextField txtSelID;
	private JTextField txtID;
    private JTextField txtName;
    //private JTextField txtCourseName;
    private JButton btnOk;
    private JButton btnCancel;
    private JFrame parent;
    
    public CourseSelectPanel(JFrame parent) {
        this.parent = parent;
        setLayout(null);
        JLabel jLabel = new JLabel("查询的课程ID:");
        jLabel.setBounds(500, 200, 70, 30);
        add(jLabel);
        txtSelID = new JTextField();
        txtSelID.setBounds(570, 200, 200, 30);
        add(txtSelID);
        
        JLabel jLabel2 = new JLabel("课程ID:");
        jLabel2.setBounds(500, 250, 70, 30);
        add(jLabel2);
        txtID = new JTextField();
        txtID.setBounds(570, 250, 200, 30);
        add(txtID);
        txtID.setEditable(false);
        
        JLabel jLabel21 = new JLabel("课程名:");
        jLabel21.setBounds(500, 300, 70, 30);
        add(jLabel21);
        txtName = new JTextField();
        txtName.setBounds(570, 300, 200, 30);
        add(txtName);
        txtName.setEditable(false);
        
        
        btnOk = new JButton("确定");
        btnOk.setBounds(520, 400, 80, 30);
        add(btnOk);
        
        btnOk.addActionListener(new ActionListener() {
            @SuppressWarnings("null")
			@Override
            public void actionPerformed(ActionEvent e) {
            	/*BjBean bjBean = (BjBean )jComboBox.getSelectedItem();
            	System.out.println(bjBean.getBjID()+","+bjBean.getBjname());*/
                if (txtSelID.getText().isEmpty()) {
                    JOptionPane.showMessageDialog(null, "课程ID不能为空", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                /*if (txtName.getText().isEmpty()) {
                    JOptionPane.showMessageDialog(null, "课程名称不能为空", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }*/
                CourseBean courseBean = new CourseBean();
                courseBean.setCourseID(txtSelID.getText());
                //StudentBean.setStudentName(txtName.getText());
                CourseBean rtn = CourseService.courseService.select(courseBean);
                if (rtn ==null) {
                    JOptionPane.showMessageDialog(null,"查询失败,课程不存在", "错误", JOptionPane.ERROR_MESSAGE);
                    txtSelID.setText("");
                    txtID.setText("");
                    txtName.setText("");
                    //txtCourseName.setText("");
                }
                else {
                    //txtCourseName.setText(rtn.getCourseName());
                    txtID.setText(rtn.getCourseID());
                    txtName.setText(rtn.getCourseName());
                    txtSelID.setText("");
                }

            }
        });
        btnCancel = new JButton("取消");
        btnCancel.setBounds(680,400,80,30);
        add(btnCancel);
        btnCancel.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cancel();
            }
        });
    }
   
	protected void cancel(){
        parent.remove(this);
        parent.validate();
        parent. Repaint();
    }


}

服务

1.班级服务(cs.practics.service.BjService.java)

package cs.practics.service;

import java.beans.beancontext.BeanContext;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import cs.practics.bean.BjBean;
import cs.practics.bean.StudentBean;

public class BjService {
	 public static final String dz1 = "E:/java实训/bj/data/data.data";
	    private List<BjBean> list = null;
	    public static BjService bjService = new BjService();
	    private  BjService(){
	        try{
	            list = FileUtil.loadData(dz1);
	        }catch (ClassNotFoundException| IOException e){
	            e.printStackTrace();
	        }
	        if(list==null)list = new ArrayList<>();
	    }
	    public BjBean searchByBjID(String bjID){
	        for(BjBean bjBean:list){
	            if(bjBean.getBjID().equals(bjID)) return bjBean;
	        }
	        return null;
	    }
	    public int add(BjBean bean){
	        try {
	        	BjBean tmp = searchByBjID(bean.getBjID());
	            if (tmp !=null) return -2;
	            list.add(bean);
	            FileUtil.writeData(list,dz1);
	            return 1;
	        }catch (Exception e){
	            e.printStackTrace();
	            return -1;
	        }
	    }
		public List<BjBean> list() {
			// TODO Auto-generated method stub
			return list;
		}
		public Integer add(StudentBean studentBean) {
			// TODO Auto-generated method stub
			return add(studentBean);
		}
		public BjBean select(BjBean bjBean) {
			// TODO Auto-generated method stub
			BjBean rtn = searchByBjID(bjBean.getBjID());
			if(rtn != null) {
				return rtn;
			}else {
				return null;
			}
		}
}

2.课程服务(cs.practics.service.CourseService.java)

package cs.practics.service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import cs.practics.bean.BjBean;
import cs.practics.bean.CourseBean;

public class CourseService {
	public static final String dz = "E:/java实训/course/data/data.data";
    private List<CourseBean> list = null;
    public static CourseService courseService = new CourseService();
    
    private  CourseService(){
        try{
            list = FileUtil.loadData(dz);
            
        }catch (ClassNotFoundException| IOException e){
            e.printStackTrace();
        }
        if(list==null)list = new ArrayList<>();
    }
    public CourseBean searchByCourseID(String courseID){
        for(CourseBean courseBean:list){
            if(courseBean.getCourseID().equals(courseID)) return courseBean;
        }
        return null;
    }
    public int add(CourseBean bean){
        try {
            CourseBean tmp = searchByCourseID(bean.getCourseID());
            if (tmp !=null) return -2;
            list.add(bean);
            FileUtil.writeData(list,dz);
            return 1;
        }catch (Exception e){
            e.printStackTrace();
            return -1;
        }
    }
	public List<CourseBean> list() {
		// TODO Auto-generated method stub
		return list;
	}
	public CourseBean select(CourseBean courseBean) {
		// TODO Auto-generated method stub
		CourseBean rtn = searchByCourseID(courseBean.getCourseID());
		if(rtn != null) {
			return rtn;
		}
		else {
			return null;
		}
		
	}
	
}

3.成绩服务(cs.practics.service.MarkService.java)

package cs.practics.service;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cs.practics.bean.CourseBean;
import cs.practics.bean.MarkBean;
import cs.practics.bean.StudentBean;

public class MarkService {
	private List<MarkBean> list = null;
	public final String PATH = "E:/java实训/mark/data/data.data";
	
	public static MarkService markService = new MarkService();
	
	private MarkService() {
		try {
			list = FileUtil.loadData(PATH);
		} catch (ClassNotFoundException | IOException e) {
			e.printStackTrace();
		}
		if (list == null) list = new ArrayList<>();
	}
	/**
	 * 从mark库找出对应课程和班级的分数列表
	 * @param classID
	 * @param courseID
	 * @return
	 */
	public List<MarkBean> searchByBjIDAndCourseID(String bjID, String courseID) {
		List<MarkBean> marks = new ArrayList<>();
		for (MarkBean markBean: list) {
			if (markBean.getBjID().equals(bjID) && markBean.getCourseID().equals(courseID)) {
				marks.add(markBean);
			}
		}
		return marks;
	}
	/**
	 * 从学生库找出该班级的学生,并且以List<MarkBean>返回
	 * @param classID
	 * @return
	 */
	public List<MarkBean> searchByBjIDAndCourseID(String bjID, CourseBean courseBean){
		List<MarkBean> marks = new ArrayList<>();
		List<StudentBean> students = StudentService.studentService.getByBjID(bjID);
		if (students != null && students.size() > 0) {
			for (StudentBean studentBean: students) {
				MarkBean markBean = new MarkBean();
				markBean.setBjID(studentBean.getBjID());
				markBean.setBjName(studentBean.getBjname());
				markBean.setCourseID(courseBean.getCourseID());
				markBean.setCourseName(courseBean.getCourseName());
				markBean.setStudentName(studentBean.getStudentname());
				markBean.setStudentID(studentBean.getStudentID());
				marks.add(markBean);
			}
		}
		return marks;
	}
	public List<MarkBean> searchByCourseAndClass(String courseID, String bjID){
		List<MarkBean> markList = new ArrayList<>();
		for (MarkBean markBean : list) {
			if (markBean.getBjID().equals(bjID) && markBean.getCourseID().equals(courseID)) {
				markList.add(markBean);
			}
		}
		return markList;
	}
	public List<MarkBean> searchByStuID(String studentID){
		List<MarkBean> marks =new ArrayList<>();
		for (MarkBean markBean:list){
			if (markBean.getStudentID().equals(studentID)){
				marks.add(markBean);
			}
		}
		return marks;
	}
	public List<MarkBean> search(String bjID, CourseBean courseBean){
		List<MarkBean> marks;
		marks = searchByBjIDAndCourseID(bjID, courseBean.getCourseID());
		if (marks == null || marks.size() == 0) {
			marks = searchByBjIDAndCourseID(bjID, courseBean);
		}
		return marks;
	}
	public  void sumbit(List<MarkBean> marks){
		for (MarkBean markBean:marks){
			MarkBean tmp = null;
			for (int i=0;i<list.size();i++){
				tmp = list.get(i);
				if (markBean.getStudentID().equals(tmp.getStudentID())&&markBean.getCourseID().equals(tmp.getCourseID())){
					break;
				}
				tmp = null;
			}
			if (tmp == null){
				list.add(markBean);
			}else {
				tmp.setMark(markBean.getMark());
			}
		}
		try{
			FileUtil.writeData(list,PATH);
		}catch (IOException e){
			e.printStackTrace();
		}
	}
	@SuppressWarnings("deprecation")
	public Map<String, String> counter(String courseID, String bjID) {
		List<MarkBean> list = searchByCourseAndClass(courseID, bjID);
		if (list == null || list.size() == 0) return null;
		Map<String, String> map = new HashMap<>();
		BigDecimal max = null;
		BigDecimal min = null;
		BigDecimal sum = new BigDecimal(0);
		for (MarkBean mark: list) {
			if (mark.getMark() == null) continue;

			if (max == null) {
				max = mark.getMark();
				min = mark.getMark();
			}

			if (mark.getMark().compareTo(max) > 0) {
				max = mark.getMark();
			}
			if (mark.getMark().compareTo(min) < 0) {
				min = mark.getMark();
			}
			sum = sum.add(mark.getMark());
		}
		sum = sum.divide(new BigDecimal(list.size()),1,BigDecimal.ROUND_DOWN);
		map.put("最高分", max.toString());
		map.put("最低分", min.toString());
		map.put("平均分", sum.toString());
		return map;
	}
	public List<MarkBean> list(){
		return list;
	}
}

4.学生服务(cs.practics.service.StudentService.java)

package cs.practics.service;

import java.util.ArrayList;
import java.util.List;

import cs.practics.bean.BjBean;
import cs.practics.bean.CourseBean;
import cs.practics.bean.MarkBean;
import cs.practics.bean.StudentBean;
import cs.practics.bj.MarkInputPanel;

@SuppressWarnings("unused")
public class StudentService {
	private List<StudentBean> list = null;
	public static StudentService studentService = new StudentService();
	private StudentService() {
			try {
				list = FileUtil.loadData("E:/java实训/student/data/data.data");
			} catch (Exception e) {
				e.printStackTrace();
			}
			// TODO Auto-generated constructor stub
			if(list == null) list = new ArrayList<>();
		}
		public StudentBean searchByStudentID(String studentID) {
			for(StudentBean studentBean: list) {
				if (studentBean.getStudentID().equals(studentID)) return studentBean;
			}
			return null;
		}
		
		public int add(StudentBean studentBean,BjBean bjBean) {
			try {
				StudentBean tmp = searchByStudentID(studentBean.getStudentID());
				if(tmp!=null) return -2;
				studentBean.setBjID(bjBean.getBjID());
				studentBean.setBjName(bjBean.getBjName());
				list.add(studentBean );
				FileUtil.writeData(list,"E:/java实训/student/data/data.data");
				return 1;
			} catch (Exception e) {
				e.printStackTrace();
				return -1;
			}
		}
		public List<MarkBean> searchByBjID(String bjID, CourseBean courseBean) {
			// TODO Auto-generated method stub
			return searchByBjID(bjID, courseBean);
		}
		public List<StudentBean> getByBjID1(String classID) {
			// TODO Auto-generated method stub
			return list;
		}
		public List<StudentBean> getByBjID(String bjID) {
			// TODO Auto-generated method stub
			return list;
		}
		public StudentBean select(StudentBean studentBean) {
			// TODO Auto-generated method stub
			StudentBean rtn = searchByStudentID(studentBean.getStudentID());
			if(rtn != null) {
				return rtn;
			}else {
				return null;
			}
		}
		
		
		

	}

5.工具类(cs.practics.service.FileUtil.java)

提供IO包进行流数据处理

package cs.practics.service;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

@SuppressWarnings("serial")
public class FileUtil implements Serializable{
	 @SuppressWarnings("unchecked")
	public static <T> T loadData(String path) throws IOException,ClassNotFoundException{
	        File f = new File(path);
	        FileInputStream fis = new FileInputStream(f);
	        ObjectInputStream ois = new ObjectInputStream(fis);
	        T t = (T)(ois.readObject());
	        
	        ois.close();
	        return t;
	    }
	    public static void writeData(Object obj,String path) throws IOException{
	        File f = new File(path);
	        FileOutputStream fos = new FileOutputStream(f);
	        ObjectOutputStream oos = new ObjectOutputStream(fos);
	        oos.writeObject(obj);
	        oos.flush();
	        oos.close();
	    }
}

该程序的书写目前没有写完,还是很基础的一个系统,后续会跟进更新代码

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/26649.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Spring Cloud 容错机试 Hystrix 服务降级 RestTemplate:

Ribon的服务降级操作 雪崩效应&#xff1a; 如果短信服务炸了后面的所有服务就会起连锁反应造成全部服务挂掉&#xff0c;这就是雪崩效应&#xff0c;那么其实短信服务又不是我们主要业务&#xff0c;这个时候我们可以采用服务降级&#xff0c;服务降级就是暂时的把短信服务停…

springboot服务端接口公网远程调试 - 实现HTTP服务监听【端口映射】

文章目录 前言1. 本地环境搭建1.1 环境参数1.2 搭建springboot服务项目 2. 内网穿透2.1 安装配置cpolar内网穿透2.1.1 windows系统2.1.2 linux系统 2.2 创建隧道映射本地端口2.3 测试公网地址 3. 固定公网地址3.1 保留一个二级子域名3.2 配置二级子域名3.2 测试使用固定公网地址…

安装CHATGPT保姆级教程(windows版)

ai包链接&#xff1a; 链接&#xff1a;https://pan.baidu.com/s/1tKuG4OfkewlDRU292vx8mw?pwdtw8t 提取码&#xff1a;tw8t 一、安装篇 安装python&#xff0c;使用软件包中的python安装程序安装后检查是否安装成功&#xff0c;cmd窗口运行命令&#xff1a; python –vers…

python自动化爬虫实战

python自动化爬虫实战 偶然的一次机会再次用到爬虫&#xff0c;借此机会记录一下爬虫的学习经历&#xff0c;方便后续复用。 需求&#xff1a;爬取网站数据并存入的csv文件中&#xff0c;总体分为两步 爬取网站数据存到到csv文件中 1、配置爬虫环境 1.1、下载自动化测试驱动 …

【2023最新】Python + Pycharm + Anaconda安装配置一条龙

【2023最新】Python Pycharm Anaconda安装配置一条龙 文章目录 【2023最新】Python Pycharm Anaconda安装配置一条龙1. Python1.1 Python下载1.2 Python安装1.3 测试 2. Pycharm2.1 Pycharm下载2.2 Pycharm安装配置2.3 你好Pycharm 3. Anaconda3.1 Anaconda下载3.2 Anacond…

【网络】TCP通讯(三次握手、四次挥手;滑动窗口;TCP状态转换;端口复用;TCP心跳检测机制)

前言&#xff1a;建议看着图片&#xff0c;根据文字描述走一遍TCP通讯过程&#xff0c;加深理解。 目录 TCP通信时序&#xff1a; 1&#xff09;建立连接&#xff08;三次握手&#xff09;的过程&#xff1a; 2&#xff09;数据传输的过程&#xff1a; 3&#xff09;关闭连…

opencv4 傅里叶变换

傅里叶变换 ① 高频&#xff1a;变化剧烈的灰度分量&#xff0c;例如边界礁石。 ② 低频&#xff1a;变化缓慢的灰度分量&#xff0c;例如一片大海。 ③ 高通滤波器&#xff1a;只保留高频&#xff0c;会使得图像细节增强。高频边界锐化了&#xff0c;增强了&#xff0c;细节…

网瘾少年转行软件测试,月薪20k? 叛逆少年终归成长...

前言&#xff1a; 高中住校期间沉迷游戏&#xff08;DNF&#xff09;,尤其是高三那年,晚上翻墙出去通宵&#xff0c;白天上课睡觉&#xff0c;高考自然是考了个稀碎&#xff0c;高考结束那个暑假刚开始觉得整个人都自由了&#xff0c;爸妈看我没考上大学&#xff0c;知道我心情…

Sql Server 自动备份

Sql Server 自动备份 文章目录 Sql Server 自动备份1. 打开SQL Server&#xff0c;在管理下找到”维护计划”&#xff0c;右键点击”维护计划向导”&#xff0c;如图&#xff1b;2. 再次点击维护计划向导3. 在选择维护任务下勾选”备份数据库”、”清楚维护任务”4.选择需要备份…

北邮22信通:二叉树显示路径的两种方法 递归函数保存现场返回现场的实例

北邮22信通一枚~ 跟随课程进度每周更新数据结构与算法的代码和文章 持续关注作者 解锁更多邮苑信通专属代码~ 获取更多文章 请访问专栏~ 北邮22信通_青山如墨雨如画的博客-CSDN博客 一.讲解 要想实现二叉树的路径显示&#xff0c;我们要按照…

每日一题——三数之和(双指针)

每日一题 三数之和 题目链接 思路 解析函数原型 首先我们来看一下题目给的函数原型&#xff1a; int** threeSum(int* nums, int numsSize, int* returnSize, int**returnColumnSizes)题目要求我们返回一个二维数组&#xff0c;数组的行数代表着存在多少个满足条件的三元组&…

基于SVM的鸢尾花数据集回归分析

目录 1. 作者介绍2. SVM支持向量机算法2.1 鸢尾花数据集2.2 鸢尾花数据集可视化2.2.1 散点图2.2.2 箱型图2.2.3 三维散点图&#xff08;3D&#xff09; 3. SVM算法实现3.1 完整代码3.2 运行结果3.3 问题与分析 1. 作者介绍 张佳伦&#xff0c;男&#xff0c;西安工程大学电子信…

Cuda | Cudnn安装及其配置

文章目录 &#x1f449;引言&#x1f48e;一、Cuda安装1 选择Cuda版本2下载及运行安装程序3 测试 二、Cudnn安装1、进入官网下载对应cuda版本的cudnn2、下载好相应版本并进行解压安装3、解压完成后4、测试 &#x1f449;引言&#x1f48e; 学习的最大理由是想摆脱平庸&#xf…

stable diffusion图片资源分享和模型推荐,好用的模型有哪些呢?

前言 这篇文章主要是分享我的图片和推荐一些好用的模型&#xff0c;模型不在多在于精&#xff0c;基于几个好的大模型适当下载一下LORA模型&#xff0c;就能画出非常好的图片&#xff0c;多话不说 图片分享 简单展示 详情请看&#xff1a;https://space.bilibili.com/109890…

Linux基础篇 Ubuntu 22.04的环境安装-02

目录 一、资料的获取 二、安装虚拟机 三、安装Ubuntu过程 四、注意事项 一、资料的获取 1.通过官方网站下载 Ubuntu系统下载 | Ubuntuhttps://cn.ubuntu.com/download2.下载桌面板即可 3.选择下载的版本 二、安装虚拟机 1.创建新的虚拟机 2.选择自定义安装 3.硬件兼容性选…

Es elasticsearch 十九 kibana 可视化配置图表 及功能 集群部署

目录 Es kibana 可视化 下载zip 解压 bin/kibana.bat 启动 管理索引管理 吧logstash 存进来的数据 按照 xxx-* 方式 保存索引模式 通过 discove 配置可视化界面 图表数据实时刷新 时序图配置 饼图配置 表格数据配置 添加仪表盘 图表样例 使用后模拟绘制方法好看些 …

pandas数据预处理

pandas数据预处理 pandas及其数据结构pandas简介Series数据结构及其创建DataFrame数据结构及其创建 利用pandas导入导出数据导入外部数据导入数据文件 导出外部数据导出数据文件 数据概览及预处理数据概览分析利用DataFrame的常用属性利用DataFrame的常用方法 数据清洗缺失值处…

什么是Odoo ERP:部署方式、业务集成、成本投入、发展与未来

ERP部署的类型 如何部署ERP 系统&#xff1f;通过多年的发展&#xff0c;ERP系统的部署方式更加多样化&#xff0c;包括公有云或私有云部署、本地部署或整合不同环境的混合部署场景&#xff0c;企业可根据自身条件与应用场景加以选择。下面介绍了每种部署模式的主要优势&#…

动态规划-硬币排成线

动态规划-硬币排成线 1 描述2 样例2.1 样例 1:2.2 样例 2:2.3 样例 3: 3 算法解题思路及实现3.1 算法解题分析3.1.1 确定状态3.1.2 转移方程3.1.3 初始条件和边界情况3.1.4 计算顺序 3.2 算法实现3.2.1 动态规划常规实现3.2.2 动态规划滚动数组 该题是lintcode的第394题&#x…

在简历上写了“精通”后,我差点被面试官问到窒息....

前言 如果有真才实学&#xff0c;写个精通可以让面试官眼前一亮&#xff01; 如果是瞎写&#xff1f;基本就要被狠狠地虐一把里&#xff01; 最近在面试&#xff0c;我现在十分后悔在简历上写了“精通”二字… 先给大家看看我简历上的技能列表&#xff1a; 熟悉软件测试理…