JAVA语言程序设计实验 (新)-学生信息管理系统

  • 需求分析

程序设计的任务是实现对学生信息的管理。用户名和密码都默认设置为0,用户名或密码输入错误会弹出“用户名或密码输入不正确”的对话框。在用户名和密码输入正确后进入学生信息管理系统,然后进行添加、修改、删除、统计等操作。添加学生记录:输入学号、姓名、高等数学、英语。点击保存则自动跳转显示学生记录列表的页面。来分页展示学生记录列表。这个页面有查询,删除,修改,退出显示等按钮。

  • 概要设计

1、类之间的调用关系

 

2、学生信息E-R图

 

  • 详细设计
    1. 主程序Starter的代码

 

主要实现了信息管理窗口,还有对各个服务的依赖掉用等功能。

package com.paper.view;

import com.paper.entity.Statistics;
import com.paper.entity.Student;
import com.paper.service.StudentService;
import com.paper.table.MyJTable;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Starter {
    public static void main(String args[])throws Exception{
        new Starter().init();
    }
    private JFrame jf=new JFrame("学生信息管理系统");
    Dimension faceSize=new Dimension(800,600);
    private Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
    //按学号查询
    private JPanel pSelect=new JPanel();
    private JButton bNoSelect=new JButton("按学号序显示");
    private JButton bNameSelect=new JButton("按姓名序显示");
    private JButton bScoreSelect=new JButton("按成绩序显示");
    private JButton bLogout=new JButton("退出系统");
    //查询结果放在一个JTable
    private MyJTable table;
    private DefaultTableModel tableModel;
    private JScrollPane tableScrollPane;
    private Object[] tableTitle={"学号","姓名","计算机","高等数学","英语"};
    private Object[][]tableData={new Object[]{""}};
    //对学生信息进行管理的添加、删除、修改按钮
    private JPanel buttonPanel=new JPanel();
    private JButton insert=new JButton("添加");
    private JButton delete=new JButton("删除");
    private JButton update=new JButton("修改");
    private JButton statistics=new JButton("统计");
    //单机添加、修改时弹出的对话框
    private JDialog dialog=new JDialog(jf,"学生管理");
    private Box box=Box.createVerticalBox();
    private JPanel pPhoto=new JPanel(new FlowLayout(FlowLayout.LEFT));
    private JPanel pId=new JPanel(new FlowLayout(FlowLayout.LEFT));
    private JPanel pName=new JPanel(new FlowLayout(FlowLayout.LEFT));
    private JPanel pComputer=new JPanel(new FlowLayout(FlowLayout.LEFT));
    private JPanel pAdvancedMath=new JPanel(new FlowLayout(FlowLayout.LEFT));
    private JPanel pEnglish=new JPanel(new FlowLayout(FlowLayout.LEFT));
    private JLabel lId=new JLabel("学 号");
    private JLabel lName=new JLabel("姓 名");
    private JLabel lComputer=new JLabel("计算机");
    private JLabel lAdvancedMath=new JLabel("高等数学");
    private JLabel lEnglish=new JLabel("英 语");
    private JTextField tId=new JTextField(15);
    private JTextField tName=new JTextField(15);
    private JTextField tComputer= new JTextField(15);
    private JTextField tAdvancedMath=new JTextField(15);
    private JTextField tEnglish=new JTextField(15);
    private JPanel pButton=new JPanel();
    private JButton confirm=new JButton("确认");
    private JButton cancel=new JButton("取消");
    private StudentService service=new StudentService();
    //用于标记是添加还是修改
    private String id;
    public void init(){
        pSelect.add(bNoSelect);
        pSelect.add(bNameSelect);
        pSelect.add(bScoreSelect);
        pSelect.add(bLogout);
        //查询按钮的监听器
        bNoSelect.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e){
                java.util.List<Student> student = service.selectAll(1);
                clearTable();
                for(Student s:student){
                    insertTable(s);
                }
            }
        });

        //查询按钮的监听器
        bNameSelect.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e){
                java.util.List<Student> student = service.selectAll(2);
                clearTable();
                for(Student s:student){
                    insertTable(s);
                }
            }
        });

        //查询按钮的监听器
        bScoreSelect.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e){
                java.util.List<Student> student = service.selectAll(3);
                clearTable();
                for(Student s:student){
                    insertTable(s);
                }
            }
        });

        //退出系统
        bLogout.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e){
                System.exit(0);
            }
        });
        //table
        tableModel=new DefaultTableModel(tableData,tableTitle);
        table=new MyJTable(tableModel);
        tableScrollPane=new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED  );
        //button
        buttonPanel.add(insert);
        buttonPanel.add(delete);
        buttonPanel.add(update);
        buttonPanel.add(statistics);
        //添加按钮的监听器
        insert.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e){
                //如果是添加,则将id=null;
                id=null;
                tId.setText("");
                tId.setEditable(true);
                tName.setText("");
                tComputer.setText("");
                tAdvancedMath.setText("");
                tEnglish.setText("");
                dialog.setVisible(true);

            }
        });
        //删除按钮的监听器
        delete.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e){
                //获得选择删除的行号数组
                int[] selected=table.getSelectedRows();
                //如果selected的长度为0,说明没有选择要删除的
                if(selected.length==0){
                    JOptionPane.showMessageDialog(jf, "请选择要删除的信息!","提示",JOptionPane.WARNING_MESSAGE );
                }else{
                    //提示是否要进行删除
                    int flag=JOptionPane.showConfirmDialog(jf, "确认删除吗?","提示",JOptionPane.WARNING_MESSAGE );
                    //如果选择是,则进行删除
                    if(flag==JOptionPane.OK_OPTION ){
                        for(int i=selected.length-1;i>=0;i--){
                            service.delete((String)tableModel.getValueAt(selected[i], 0));
                            tableModel.removeRow(selected[i]);
                        }
                    }
                }
            }
        });
        //统计按钮的监听器
        statistics.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e){
                Statistics statistics = service.statistics();
                new StatisticsView().init(statistics);
            }
        });

        //修改按钮的监听器
        update.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e){
                int row=table.getSelectedRow();
                //如果要进行修改,就将id=要修改的学号
                id=String.valueOf(table.getValueAt(row, 0));
                //设置tId的内容
                tId.setText(id);
                //设置tId不可修改
                tId.setEditable(false);
                tName.setText(String.valueOf(table.getValueAt(row, 1)));
                tComputer.setText(String.valueOf(table.getValueAt(row, 2)));
                tAdvancedMath.setText(String.valueOf(table.getValueAt(row, 3)));
                tEnglish.setText(String.valueOf(table.getValueAt(row, 4)));
                //设置dialog可见
                dialog.setVisible(true);
            }
        });
        jf.setLayout(new BorderLayout());
        //设置pSelect在jf的北面
        jf.add(pSelect,BorderLayout.NORTH);
        //设置pSelect在jf的中心
        jf.add(tableScrollPane,BorderLayout.CENTER );
        //设置pSelelct在jf的南面
        jf.add(buttonPanel,BorderLayout.SOUTH);
        jf.pack();
        jf.setSize(faceSize);
        jf.setLocation((int)(screenSize.width-faceSize.getWidth())/2,(int)(screenSize.height-faceSize.getHeight())/2);
        jf.setResizable(false);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setVisible(true);
        pId.add(lId);
        pId.add(tId);
        pName.add(lName);
        pName.add(tName);
        pComputer.add(lComputer);
        pComputer.add(tComputer);
        pAdvancedMath.add(lAdvancedMath);
        pAdvancedMath.add(tAdvancedMath);
        pEnglish.add(lEnglish);
        pEnglish.add(tEnglish);
        pButton.add(confirm);
        pButton.add(cancel);
        //确定按钮的监听器
        confirm.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e){
                Student student=new Student();
                student.setUserId(tId.getText());
                student.setPassword(tId.getText());
                student.setId(tId.getText());
                student.setName(tName.getText());
                student.setComputer(toDouble(tComputer.getText()));
                student.setAdvancedMath(toDouble(tAdvancedMath.getText()));
                student.setEnglish(toDouble(tEnglish.getText()));
                if(id!=null){
                    service.update(student);
                }else{
                    service.insert(student);
                }
                dialog.dispose();

            }
        });
        //取消按钮的监听器
        cancel.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e){
                dialog.dispose();
            }
        });
        box.add(pPhoto);
        box.add(pId);
        box.add(pName);
        box.add(pComputer);
        box.add(pAdvancedMath);
        box.add(pEnglish);
        box.add(pButton);
        box.add(pButton);
        dialog.add(box);
        dialog.setBounds((int)(screenSize.width-280)/2,(int)(screenSize.height-300)/2,280,350);
    }
    public void insertTable(Student student){
        if(student!=null){
            String[]newCell=new String[7];
            newCell[0]=student.getId();
            newCell[1]=student.getName();
            newCell[2]=student.getComputer().toString();
            newCell[3]=student.getAdvancedMath().toString();
            newCell[4]=student.getEnglish().toString();
            tableModel.addRow(newCell);
        }
    }
    public void clearTable(){
        int rows=tableModel.getRowCount();
        for(int i=0 ;i<rows;i++){
            tableModel.removeRow(0);
        }
    }

    public Double toDouble(String doubleStr) {
        try {
            if(doubleStr == null || "".equals(doubleStr)){
                return 0D;
            }
            return Double.valueOf(doubleStr);
        } catch (Exception e) {
            System.err.println("数据转换错误,分数不是实数");
            return 0d;
        }
    }
}

    1. StudentService服务类代码

实现了具体的业务,对数据的增删改查统计等功能

package com.paper.service;

import com.paper.entity.Statistics;
import com.paper.entity.Student;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;


public class StudentService{

    private Map<String, Student> students= new ConcurrentHashMap<String, Student>();

    //添加学生信息
    public void insert(Student s){
        if(! students.containsKey(s.getId())){
            students.put(s.getId(),s);
            System.out.println("添加成功!");
        }else{
            System.err.println("学号重复了");
        }
    }

    //删除学生信息
    public void delete(String userId){
        students.remove(userId);
        System.out.print("删除成功!");
    }
    //修改学生信息
    public void update(Student s){
        String userId=s.getUserId();
        students.remove(userId);
        students.put(userId,s);
    }
    //按学号查询
    public Student selectById(String userId){
        return students.get(userId);
    }
    //查询所有学生信息
    public List<Student> selectAll(int sorted){
        List<Student> studentList = new ArrayList<Student>(students.values());
        switch (sorted){
            case 1:
                studentList = studentList.stream().sorted(Comparator.comparing(Student::getId)).collect(Collectors.toList());
                break;
            case 2:
                studentList = studentList.stream().sorted(Comparator.comparing(Student::getName)).collect(Collectors.toList());
                break;
            case 3:
                studentList = studentList.stream().sorted(Comparator.comparing(student -> {
                    Double computer = student.getComputer();
                    Double advancedMath = student.getAdvancedMath();
                    Double english = student.getEnglish();
                    Double sum = computer+advancedMath+english;
                    return sum;
                })).collect(Collectors.toList());
                break;
            default:
                break;
        }
        return studentList;
    }

    /**
     * 统计学生信息
     * @return
     */
    public Statistics statistics(){
        List<Student> studentList = new ArrayList<Student>(students.values());
         Integer excellentQty = 0;
         Integer goodQty= 0;
         Integer averageQty= 0;
         Integer passQty= 0;
         Integer failQty= 0;
         BigDecimal highestScoreD= new BigDecimal(0);
         BigDecimal minimumScoreD= new BigDecimal(0);
         BigDecimal totalScore= new BigDecimal(0);
        for (Student student : studentList) {
            //60分以下为不及格
            int i = checkScore(student);
            switch (i){
                case 1:
                    excellentQty++;
                    break;
                case 2:
                    goodQty++;
                    break;
                case 3:
                    averageQty++;
                    break;
                case 4:
                    passQty++;
                    break;
                case 5:
                    failQty++;
                    break;
            }

            Double computer = student.getComputer();
            Double advancedMath = student.getAdvancedMath();
            Double english = student.getEnglish();
            BigDecimal computerD = new BigDecimal(computer);
            BigDecimal advancedMathD = new BigDecimal(advancedMath);
            BigDecimal englishD = new BigDecimal(english);
            BigDecimal sumDecimal = computerD.add(advancedMathD).add(englishD);
            totalScore.add(sumDecimal);
            if(highestScoreD.compareTo(sumDecimal) < 0){
                highestScoreD = sumDecimal;
            }else if(highestScoreD.compareTo(sumDecimal) > 0){
                minimumScoreD = sumDecimal;
            }
        }
        BigDecimal excellentQtyD = new BigDecimal(excellentQty);
        BigDecimal goodQtyD = new BigDecimal(goodQty);
        BigDecimal averageQtyD = new BigDecimal(averageQty);
        BigDecimal passQtyD = new BigDecimal(passQty);
        BigDecimal failQtyD = new BigDecimal(failQty);
        BigDecimal sumD = excellentQtyD.add(goodQtyD).add(averageQtyD).add(passQtyD).add(failQtyD);
        Double passRate = sumD.subtract(failQtyD).divide(sumD).doubleValue();
        Integer totalQty= sumD.intValue();
        Double excellentRatio = excellentQtyD.divide(sumD, 1, BigDecimal.ROUND_HALF_UP).doubleValue();
        Double goodRatio = goodQtyD.divide(sumD,1,BigDecimal.ROUND_HALF_UP).doubleValue();
        Double averageRatio = averageQtyD.divide(sumD,1,BigDecimal.ROUND_HALF_UP).doubleValue();
        Double passRatio = passQtyD.divide(sumD,1,BigDecimal.ROUND_HALF_UP).doubleValue();
        Double failRatio = failQtyD.divide(sumD,1,BigDecimal.ROUND_HALF_UP).doubleValue();
        Double averageScore = totalScore.divide(sumD).doubleValue();

        Statistics statistics = new Statistics();
        statistics.setExcellentQty(excellentQty);
        statistics.setExcellentRatio(excellentRatio);
        statistics.setGoodQty(goodQty);
        statistics.setGoodRatio(goodRatio);
        statistics.setAverageQty(averageQty);
        statistics.setAverageRatio(averageRatio);
        statistics.setPassQty(passQty);
        statistics.setPassRatio(passRatio);
        statistics.setFailQty(failQty);
        statistics.setFailRatio(failRatio);
        statistics.setTotalQty(totalQty);
        statistics.setPassRate(passRate);
        statistics.setHighestScore(highestScoreD.doubleValue());
        statistics.setMinimumScore(minimumScoreD.doubleValue());
        statistics.setAverageScore(averageScore);
        return statistics;
    }

    /**
     * 校验学生是分数
     * 100分满分
     * 总分大于等于270分为优秀 返回1
     * 总分大于等于240分且小于270分为良好 返回2
     * 总分大于等于210分且小于240分为中等 返回3
     * 总分大于等于180分且小于210分为及格 返回4
     * 有一科分数小于60分为不及格 返回5
     * @param student
     */
    private int checkScore(Student student) {
        Double computer = student.getComputer();
        Double advancedMath = student.getAdvancedMath();
        Double english = student.getEnglish();
        if(computer<60 || advancedMath<60 || english<60){
            return 5;
        }
        BigDecimal computerD = new BigDecimal(computer);
        BigDecimal advancedMathD = new BigDecimal(advancedMath);
        BigDecimal englishD = new BigDecimal(english);
        BigDecimal sumDecimal = computerD.add(advancedMathD).add(englishD);
        if(sumDecimal.compareTo(new BigDecimal(270)) >=0){
            return 1;
        }else if(sumDecimal.compareTo(new BigDecimal(240)) >=0){
            return 2;
        }if(sumDecimal.compareTo(new BigDecimal(210)) >=0){
            return 3;
        }else{
            return 4;
        }
    }
}

    1. Student

学生类,具体学生信息

package com.paper.entity;

public class Student extends User{
    private String id;
    private String name;
    private Double computer;
    private Double advancedMath;
    private Double english;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Double getComputer() {
        return computer;
    }

    public void setComputer(Double computer) {
        this.computer = computer;
    }

    public Double getAdvancedMath() {
        return advancedMath;
    }

    public void setAdvancedMath(Double advancedMath) {
        this.advancedMath = advancedMath;
    }

    public Double getEnglish() {
        return english;
    }

    public void setEnglish(Double english) {
        this.english = english;
    }
}


    1.  统计表
    2. package com.paper.entity;
      
      
      public class Statistics {
          private Integer excellentQty;
          private Double excellentRatio;
          private Integer goodQty;
          private Double goodRatio;
          private Integer averageQty;
          private Double averageRatio;
          private Integer passQty;
          private Double passRatio;
          private Integer failQty;
          private Double failRatio;
          private Integer totalQty;
          private Double passRate;
          private Double highestScore;
          private Double minimumScore;
          private Double averageScore;
      
          public Integer getExcellentQty() {
              return excellentQty;
          }
      
          public void setExcellentQty(Integer excellentQty) {
              this.excellentQty = excellentQty;
          }
      
          public Double getExcellentRatio() {
              return excellentRatio;
          }
      
          public void setExcellentRatio(Double excellentRatio) {
              this.excellentRatio = excellentRatio;
          }
      
          public Integer getGoodQty() {
              return goodQty;
          }
      
          public void setGoodQty(Integer goodQty) {
              this.goodQty = goodQty;
          }
      
          public Double getGoodRatio() {
              return goodRatio;
          }
      
          public void setGoodRatio(Double goodRatio) {
              this.goodRatio = goodRatio;
          }
      
          public Integer getAverageQty() {
              return averageQty;
          }
      
          public void setAverageQty(Integer averageQty) {
              this.averageQty = averageQty;
          }
      
          public Double getAverageRatio() {
              return averageRatio;
          }
      
          public void setAverageRatio(Double averageRatio) {
              this.averageRatio = averageRatio;
          }
      
          public Integer getPassQty() {
              return passQty;
          }
      
          public void setPassQty(Integer passQty) {
              this.passQty = passQty;
          }
      
          public Double getPassRatio() {
              return passRatio;
          }
      
          public void setPassRatio(Double passRatio) {
              this.passRatio = passRatio;
          }
      
          public Integer getFailQty() {
              return failQty;
          }
      
          public void setFailQty(Integer failQty) {
              this.failQty = failQty;
          }
      
          public Double getFailRatio() {
              return failRatio;
          }
      
          public void setFailRatio(Double failRatio) {
              this.failRatio = failRatio;
          }
      
          public Integer getTotalQty() {
              return totalQty;
          }
      
          public void setTotalQty(Integer totalQty) {
              this.totalQty = totalQty;
          }
      
          public Double getPassRate() {
              return passRate;
          }
      
          public void setPassRate(Double passRate) {
              this.passRate = passRate;
          }
      
          public Double getHighestScore() {
              return highestScore;
          }
      
          public void setHighestScore(Double highestScore) {
              this.highestScore = highestScore;
          }
      
          public Double getMinimumScore() {
              return minimumScore;
          }
      
          public void setMinimumScore(Double minimumScore) {
              this.minimumScore = minimumScore;
          }
      
          public Double getAverageScore() {
              return averageScore;
          }
      
          public void setAverageScore(Double averageScore) {
              this.averageScore = averageScore;
          }
      }
      

    3. User

用户类。如果登录用于登录操作 

package com.paper.entity;


public class User {
    private String userId;
    private String password;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

    1. StatisticsView

用于展示统计信息

package com.paper.view;



import com.paper.entity.Statistics;
import com.paper.table.MyJTable;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;

public class  StatisticsView{

    private JFrame jf=new JFrame("学生信息管理系统");
    Dimension faceSize=new Dimension(800,600);
    private Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();

    private DefaultTableModel tableModel;
    private Object[] tableTitle={"统计学生记录"};
    private Object[][]tableData={new Object[]{""}};
    private MyJTable table;
    private JScrollPane tableScrollPane;

    private Box box=Box.createVerticalBox();


    public void init(Statistics statistics) {
        jf.setResizable(false);
        jf.setVisible( true);
        jf.pack();
        //用户单击窗口的关闭按钮时程序执行的操作
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setLocation((int)(screenSize.width-faceSize.getWidth())/2,(int)(screenSize.height-faceSize.getHeight())/2);
        //table
        tableModel=new DefaultTableModel(tableData,tableTitle);
        table=new MyJTable(tableModel);
        tableScrollPane=new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED  );
        //设置pSelect在jf的中心
        jf.add(tableScrollPane,BorderLayout.CENTER );
        jf.setSize(faceSize);

        //封装表格
        showStatisticsTable(statistics);
    }

    private void showStatisticsTable(Statistics statistics) {
        clearTable();
        insertTable("优秀学生人数:"+ integerToString(statistics.getExcellentQty()));
        insertTable("优秀学生占比:"+ doubleToString(statistics.getExcellentRatio()));
        insertTable("良好学生人数:"+ integerToString(statistics.getGoodQty()));
        insertTable("良好学生占比:"+ doubleToString(statistics.getGoodRatio()));
        insertTable("中等学生人数:"+ integerToString(statistics.getAverageQty()));
        insertTable("中等学生占比:"+ doubleToString(statistics.getAverageRatio()));
        insertTable("及格学生人数:"+ integerToString(statistics.getPassQty()));
        insertTable("及格学生人数:"+ doubleToString(statistics.getPassRatio()));
        insertTable("不及格学生人数:"+ integerToString(statistics.getFailQty()));
        insertTable("不及格学生人数:"+ doubleToString(statistics.getFailRatio()));
        insertTable("总学生人数:"+ integerToString(statistics.getTotalQty()));
        insertTable("学生及格率:"+ doubleToString(statistics.getPassRate()));
        insertTable("学生成绩最高分:"+ doubleToString(statistics.getHighestScore()) +" 分");
        insertTable("学生成绩最低分:"+ doubleToString(statistics.getMinimumScore()) +" 分");
        insertTable("学生成绩平均分:"+ doubleToString(statistics.getAverageScore()) +" 分");
    }

    private String doubleToString(Double value) {
        if(value == null){
            return "";
        }
        return String.valueOf(value);
    }

    private String integerToString(Integer value) {
        if(value == null){
            return "";
        }
        return String.valueOf(value)+" 人";
    }

    public void insertTable(String value){
        System.out.println(11111);
        if(value!=null && ! "".equals(value)){
            String[]newCell=new String[1];
            newCell[0]=value;
            tableModel.addRow(newCell);
        }
    }

    public void clearTable(){
        int rows=tableModel.getRowCount();
        for(int i=0 ;i<rows;i++){
            tableModel.removeRow(0);
        }
    }

    public static void main(String[] args) {
        Statistics statistics = new Statistics();
        new StatisticsView().init(statistics);
    }
}

    1. MyJTable

自定义的table类,继承自JTable

package com.paper.table;


import javax.swing.*;
import javax.swing.table.TableModel;

public class MyJTable extends JTable {
    /**
     *
     */
    private static final long serialVersionUID = -3083638370004874364L;
    public MyJTable(TableModel dm){
        super(dm);
    }
    //设置表格不可编辑
    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex){
        return false;
    }
}

  • 调试结果展示
    1. 主页面

     

    1. 添加学生记录

     

    1. 显示学生记录

     

     

     

    1. 删除学生记录

     

     

     

    1. 查询学生记录

同显示学生记录

    1. 统计学生记录

     

    1. 退出系统

点击关闭退出系统或直接退出

 

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
实验5 常用类(2学时) 一、实验目的 1. 熟悉Java中的String、StringBuffer、Math、包装器类的使用方法。 2. 使用常用类解决一般性的应用问题。 3. 掌握JavaSE API文档的使用方法。 二、实验内容 1. 编写一个程序,输出一个字符串中的大写英文字母数,小写英文字母数以及非英文字母数。(字符串可以在main方法中指定) 2. 调用java.lang.Math的成员函数“public static double random()”运算下面表达式1000次,(int) (Math.random()*20+0.5),统计其中生成的整数0、1、2、……、20的个数分别是多少,并输出统计结果。 3. 编写一个方法,返回一个double型的二维数组,数组中的元素通过解析字符串参数获得。例如,字符串参数:“1,2;3,4,5;6,7,8”,对应的数组为: d[0,0] = 1.0 d[0,1] = 2.0 d[1,0] = 3.0 d[1,1] = 4.0 d[1,2] = 5.0 d[2,0] = 6.0 d[2,1] = 7.0 d[2,2] = 8.0 三、实验要求 完成程序设计并提交实验报告。 实验6 容器(2学时) 一、实验目的 1. 熟悉容器类库中常用类的使用方法。 2. 使用常用容器类解决一般性的应用问题。 二、实验内容 1. 用HashMap模拟一个网上购物车。要求:从键盘输入5本书的名称、单价、购买数量,将这些信息存入一个HashMap,然后将该HashMap作为参数调用方法getSum(HashMap books),该方法用于计算书的总价并返回。【说明:键盘输入可以使用Scanner类】 2. 使用两个Stack类(JDK容器类库中的Stack类)实现一个队列类MyQueue,提供队列的入队列和出队列操作:enQueue和deQueue。 3. 写一个彩票程序:30选7。随机(1~30之间)生成7个随机数,注意不能重复。然后从键盘输入7个数,对比7个数是否与随机数有相同的。最后显示“中了几个号”。同时,如果中了7个号,显示一等奖;如果中了6个号,显示二等奖;如果中了5个号,显示三等奖。要求:首先写出程序的实现思想,特别是程序所使用的数据结构,然后写出Java实现代码。【说明:键盘输入可以使用Scanner类】 三、实验要求 完成程序设计并提交实验报告。 实验7 流(2学时) 一、实验目的 1. 熟悉流类库中各种常用流的使用方法。 2. 能够使用流类实现基本的文件读写。 二、实验内容 1. 编写程序,在控制台窗口提示输入两个整数,然后接收这两个整数,并输出它们的和。(要求:键盘输入通过流封装System.in获取,不要使用Scanner类) 2. 设计学生类Student,属性:编号(整型);姓名(字符串),成绩(整型)。编写一个程序:要求:(1)输入5个学生的姓名和成绩,将其姓名和成绩保存到data.txt中;(2)然后从该文件中读取数据,求得这五个学生的平均成绩。 三、实验要求 完成程序设计并提交实验报告。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值