JAVA 学生管理系统

时间:2022-11-13 22:19:45
"-----学生管理系统-----"
"功能选项:"
"1:新增学生"
"2:删除学生"
"3:修改学生"
"4:查找学生"
"5:查看全部学生"
"6:退出"
  1 public class 学生管理系统 {
  2     public static void main(String[] args) {
  3         String[] name1 = new String[100];
  4         int[] chengji1 = new int[100];
  5         int count = 0;
  6         while (true) {
  7             int choose = chooseFunction();
  8             switch (choose) {
  9                 case 1:
 10                     count = add(name1, chengji1, count);
 11                     break;
 12                 case 2:
 13                     count = delete(name1, chengji1, count);
 14                     break;
 15                 case 3:
 16                     change(name1, chengji1, count);
 17                     break;
 18                 case 4:
 19                     find(name1, chengji1, count);
 20                     break;
 21                 case 5:
 22                     update(name1, chengji1, count);
 23                     break;
 24                 case 6:
 25                     exit();
 26                     return;
 27                 default:
 28                     System.out.println("----------------------------------");
 29                     System.out.println("功能选择有误,请输入正确的功能序号!");
 30                     break;
 31             }
 32         }
 33     }
 34         public static int chooseFunction() {
 35             System.out.println("-----学生管理系统-----");
 36             System.out.println("功能选项:");
 37             System.out.println("1:新增学生");
 38             System.out.println("2:删除学生");
 39             System.out.println("3:修改学生");
 40             System.out.println("4:查找学生");
 41             System.out.println("5:查看全部学生");
 42             System.out.println("6:退出");
 43             //接收键盘输入的功能选项序号
 44             Scanner sc = new Scanner(System.in);
 45             System.out.print("请输入选项:");
 46             int choose = sc.nextInt();
 47             return choose;
 48         }
 49         public static int add(String[]name1,int[]chengji1,int count){
 50             System.out.print("添加人姓名:");
 51             name1[count]=new Scanner(System.in).next();
 52             System.out.print("添加人成绩:");
 53             chengji1[count]=new Scanner(System.in).nextInt();
 54             System.out.println("添加成功");
 55             count++;
 56             System.out.println("添加数量为:"+count+"  ");
 57             return count;
 58 
 59         }
 60         public static void update(String[]name1,int[]chengji1,int count){
 61         for (int i=0;i<count;i++){
 62             System.out.println("姓名    成绩");
 63             System.out.println(name1[i]+"    "+chengji1[i]);
 64         }
 65         }
 66         public static int delete(String[]name1,int[]chengji1,int count){
 67             System.out.print("请输入需要删除的学生: ");
 68             String n=new Scanner(System.in).next();
 69             for(int i=0;i<count;i++){
 70                 if (n.equals(name1[i])){
 71                    name1[i]=name1[i+1];
 72                    chengji1[i]=chengji1[i+1];
 73                 }
 74             }
 75             count-=1;
 76             System.out.println("删除学生"+n+"成功");
 77             return count;
 78 
 79     }
 80         public static void change(String[]name1,int[]chengji1,int count){
 81             System.out.print("输入要修改的学生姓名:");
 82             String name=new Scanner(System.in).next();
 83             for (int i=0;i<count;i++){
 84                 if (name.equals(name1[i])){
 85                     System.out.println("原姓名:  "+name1[i]+"原成绩:  "+chengji1[i]);
 86                     System.out.print("输入修改的姓名:");
 87                     name1[i] = new Scanner(System.in).next();
 88                     System.out.print("输入修改的成绩:");
 89                     chengji1[i] = new Scanner(System.in).nextInt();
 90                     System.out.println("修改成功");
 91                     return;
 92                 }
 93             }System.out.println("查无此人");
 94         }
 95         public static void find(String[]name1,int[]chengji1,int count){
 96             System.out.print("请输入需要查找的学生姓名:  ");
 97             String name=new Scanner(System.in).next();
 98                 for (int i=0;i<count;i++){
 99                     if (name.equals(name1[i])){
100                          System.out.println("学生:  "+name1[i]+"成绩:  "+chengji1[i]);
101                          return;
102                     }
103                 }
104                 System.out.println("查无此人");
105         }
106         public static void exit(){
107         System.out.println("----------------退出---------------");
108         System.out.println("您已退出系统");
109     }
110 }