zoukankan      html  css  js  c++  java
  • 学生管理系统(使用对象)

    学生管理系统

    要求实现登陆,学生信息的添加、显示,删除,修改,查询,排序,退出功能。

    一、首先建立学生类,用于生成学生对象

    1 package Student_Manage;
    2 
    3 public class Student {
    4     public String name ;
    5     public int score ;
    6     public int code ;
    7 }

    二、编写管理系统

      1 package Student_Manage;
      2 import javax.swing.JOptionPane;
      3 
      4 public class Manage_UseClass {
      5     
      6     public static Student [] student = new Student [20];//创建Student类的数组,用于存放学生
      7     public static int number = 0;//学生数目
      8     
      9     public static void main(String[] args) {
     10         // 学生管理系统
     11         //要求实现登陆,学生信息的添加、显示, 删除,修改,查询,排序,退出功能
     12         /**欢迎光临界面*/
     13         JOptionPane.showMessageDialog(null, "欢迎光临!");
     14         
     15         /**登陆用户名、密码验证*/
     16         String user = "111" ;
     17         String pwd = "222";
     18         for (int i = 0;i<3 ; i++){
     19             String in_user = JOptionPane.showInputDialog(null , "用户名:");
     20             String in_pwd = JOptionPane.showInputDialog(null , "密码:");
     21             if ( in_user.equals(user) && in_pwd.equals(pwd)){//判定用户名和密码是否正确
     22                 break ;
     23             }else {
     24                 JOptionPane.showMessageDialog(null, "用户名或密码错误!");
     25                 if (i==2){
     26                     JOptionPane.showMessageDialog(null, "非法用户!");
     27                     System.exit(0);
     28                 }
     29             }
     30         }
     31         
     32         /**菜单选项*/
     33         while (true){
     34             int choose_num = Integer.parseInt(JOptionPane.showInputDialog(null , "1、添加
    2、显示
    3、删除
    4、修改
    5、查询
    6、排序
    7、退出"));
     35             switch (choose_num){
     36                 case 1 : 
     37                     add() ; 
     38                     break ;
     39                 case 2 : 
     40                     show(); 
     41                     break ;
     42                 case 3 : 
     43                     del() ; 
     44                     break ;
     45                 case 4 : 
     46                     repair(); 
     47                     break ;
     48                 case 5 : 
     49                     check(); 
     50                     break ;
     51                 case 6 : 
     52                     sort(); 
     53                     break ;
     54                 case 7 : 
     55                     JOptionPane.showMessageDialog(null, "系统已退出!");
     56                     System.exit(0);
     57                     break ;
     58                 default : JOptionPane.showMessageDialog(null, "无此选项,请重新选择!");break ;
     59             }
     60         }
     61     }
     62     /**添加一个学生*/
     63     public static void add(){
     64         Student stu = new Student();
     65         stu.name = JOptionPane.showInputDialog(null,"请输入姓名:");
     66         stu.code = Integer.parseInt(JOptionPane.showInputDialog(null, "请输入学号:"));
     67         stu.score = Integer.parseInt(JOptionPane.showInputDialog(null, "请输入成绩:"));
     68         student [number] = stu ;
     69         number ++;
     70     }
     71     
     72     /**排序*/
     73     public static void sort() {
     74         Student s = new Student() ;
     75             for (int i =0;i < number ; i++){
     76                 for (int j = i; j<number;j++){
     77                     if(student [i].score < student [j].score){
     78                         s = student [i] ;
     79                         student [i] = student [j] ;
     80                         student [j] = s ;
     81                     }
     82                 }
     83             }
     84             JOptionPane.showMessageDialog(null, "排序成功!");    
     85     }
     86     /**显示*/
     87     public static void show(){
     88         String s = "学号"+"    "+"姓名"+"    "+"成绩"+"
    ";
     89         for (int i = 0 ;i< number ;i++){
     90             s+=student [i].code + "    "+ student [i].name+"    "+ student [i].score+"
    ";
     91         }
     92         JOptionPane.showMessageDialog(null, s);
     93     }
     94     /**删除*/
     95     public static void del(){
     96         int index = findByName();
     97         if (index != -1){
     98             //方法一:将最后位置的一个元素放在被删除元素的位置
     99 //        name [index] = name[ number-1];
    100 //        card [index] =card[ number-1];
    101 //        score [index] = score[ number-1];
    102 //        number--;
    103             //方法二 :连续将后一个元素填补至前一个元素
    104             for (int i = index; i <number  ; i++){
    105                 student [i] = student [i+1] ;
    106             }
    107             number--;
    108         JOptionPane.showMessageDialog(null, "删除成功!");    
    109         }
    110     }
    111     /**修改*/
    112     public static void repair(){
    113         int index = findByName();
    114         if (index !=-1){
    115             student[index].name  = JOptionPane.showInputDialog(null , "请输入新的名字:");
    116             student[index].code  = Integer.parseInt(JOptionPane.showInputDialog(null , "请输入该学生的学号"));
    117             student[index].score = Integer.parseInt(JOptionPane.showInputDialog(null , "请输入该学生的成绩"));
    118             JOptionPane.showMessageDialog(null, "修改成功!");
    119         }
    120     }
    121     /**查询*/
    122     public static void check(){
    123         int index  =findByName();
    124         if (index !=-1){
    125         JOptionPane.showMessageDialog(null,student[index].name+"
    学号:" +student[index].code+"
    成绩:"+student[index].score);
    126         }
    127     }
    128     /**代码重用---查找*/
    129     public static int findByName (){
    130         int index = -1 ;
    131         String check_name = JOptionPane.showInputDialog(null,"请输入要查询的名字:");
    132         for (int i = 0; i< number ;i++){
    133             if (check_name.equals(student[i].name)){
    134                 return i ;
    135             }
    136         }
    137         if (index == -1){
    138             JOptionPane.showMessageDialog(null, "查无此人!");
    139         }
    140         return index ;
    141     }
    142 }
  • 相关阅读:
    k8s 中 nfs作为存储的三种方式
    k8s-ingress部署测试以及深入理解
    k8s全方位监控-prometheus-配置文件介绍以及基于文件服务发现
    k8s全方位监控 -prometheus实现短信告警接口编写(python)
    prometheus-数据展示之grafana部署和数据源配置
    k8s全方位监控-prometheus-alertmanager部署-配置第一条告警邮件
    k8s全方位监控-prometheus部署
    k8s-coredns 介绍和部署
    k8s-静态PV和动态PV
    消息扩散
  • 原文地址:https://www.cnblogs.com/zzyytt/p/5852853.html
Copyright © 2011-2022 走看看