• Mini 学生管理器


     1 package Mini_xueshenguanliqi;
     2 
     3 public class Student {
     4     private int age;
     5     private String name;
     6 
     7     public Student() {
     8 
     9     }
    10 
    11     public Student(String name) {
    12 
    13     }
    14 
    15     public Student(int age) {
    16     }
    17 
    18     public Student(String name, int age) {
    19         this.name=name;
    20         this.age=age;
    21     }
    22 
    23 //返回年龄值
    24     public int getAge() {
    25         return age;
    26     }
    27 
    28 //设置年龄
    29     public void setAge(int age) {
    30         if (age > 0) {
    31             this.age = age;
    32         } else {
    33             System.out.println("年龄不合法");
    34             this.age = 0;
    35         }
    36 
    37     }
    38 
    39 //返回名字
    40     public String getName() {
    41         return name;
    42     }
    43 
    44     public void setName(String name) {
    45         this.name = name;
    46     }
    47 
    48 //重写toString() 方法
    49     public String toString() {
    50         return name + "	----	" + age;
    51     }
    52 
    53 }

      1 package Mini_xueshenguanliqi;
      2 
      3 import java.util.Scanner;
      4 
      5 public class Client {
      6     Student arr[] = new Student[5];
      7 
      8     public void initial() {
      9         Student stu1 = new Student("张三", 15);
     10         Student stu2 = new Student("李四", 14);
     11         Student stu3 = new Student("王五", 19);
     12         arr[0] = stu1;
     13         arr[1] = stu2;
     14         arr[2] = stu3;
     15         
     16         
     17         
     18 
     19     }
     20 
     21     public void start() {
     22         initial();
     23         
     24 //        调用初始化的信息;
     25         /**
     26          * 查看学生系信息
     27          */
     28         String a;
     29         do {
     30         System.out.println("欢迎进入学生管理器");
     31         System.out.println("1,查看学生信息");
     32         System.out.println("2,增加学生信息");
     33         System.out.println("3,修改学生信息");
     34         System.out.println("4,删除学生信息");
     35         System.out.println("请选择您的操作:");
     36         Scanner sc = new Scanner(System.in);
     37         int chose = sc.nextInt();
     38         
     39         
     40             switch (chose) {
     41             case 1:
     42                 showstu();
     43 //            调用函数;
     44                 break;
     45             case 2:
     46                 addstu();
     47 
     48                 break;
     49             case 3:
     50                 revisestu();
     51                 break;
     52             case 4:
     53                 deletestu();
     54                 break;
     55 
     56             default:
     57                 break;
     58             }
     59             System.out.println("是否继续,y/n");
     60              a=sc.next();
     61         } while (a.equals("y"));
     62 
     63     }
     64 
     65     /**
     66      * 输出学生信息
     67      */
     68     public void showstu() {
     69         System.out.println("现在的学生有:");
     70         System.out.println("姓名" + "	" + "---" + "	" + "年龄");
     71 
     72         for (int i = 0; i < arr.length; i++) {
     73             if (arr[i] != null) {
     74                 System.out.println(arr[i]);
     75             }
     76         }
     77     }
     78 
     79     /**
     80      * 增加学生信息
     81      */
     82     public void addstu() {
     83         Scanner sc = new Scanner(System.in);
     84         String a;
     85         do {
     86             for (int i = 0; i < arr.length; i++) {
     87             if (arr[i] == null) {
     88                 System.out.println("请输入新增学生姓名:");
     89                 String name = sc.next();
     90                 System.out.println("请输入新增学生年龄:");
     91                 int age = sc.nextInt();
     92                 arr[i] = new Student(name, age);
     93                 System.out.println("增加成功");
     94                 break;
     95             }
     96         }
     97             System.out.println("是否继续添加学生,y/n");
     98             a=sc.next();
     99         } while (a.equals("y"));
    100         
    101 
    102     }
    103 
    104     /**
    105      * 修改学生信息
    106      */
    107     public void revisestu() {
    108         Scanner sc = new Scanner(System.in);
    109         System.out.println("请输入您要修改的学生姓名:");
    110         String name = sc.next();
    111         for (int i = 0; i < arr.length; i++) {
    112             if (arr[i].getName().equals(name)) {
    113                 System.out.println("请输入修改后的姓名");
    114                 String name1 = sc.next();
    115                 System.out.println("请输入修改后的年龄");
    116                 int age = sc.nextInt();
    117                 arr[i] = new Student(name1, age);
    118                 System.out.println("修改成功");
    119                 break;
    120 //                System.out.println("你要修改1,姓名2,年龄");
    121 //                int chose=sc.nextInt();
    122 //                switch (chose) {
    123 //                case 1:
    124 //                    System.out.println("请输入修改后的姓名");
    125 //                    String name1=sc.next();
    126 //                    
    127 //                    break;
    128 //                case 2:
    129 //                    System.out.println("请输入修改后的年龄");
    130 //                    int age=sc.nextInt();
    131 //                default:
    132 //                    break;
    133 //                }
    134             }
    135         }
    136     }
    137 
    138     public void deletestu() {
    139         Scanner sc = new Scanner(System.in);
    140         System.out.println("请输入您要删除的学生姓名:");
    141         String name = sc.next();
    142         for (int i = 0; i < arr.length; i++) {
    143             if (arr[i].getName().equals(name)) {
    144 
    145                 arr[i] = null;
    146                 break;
    147             }
    148         }
    149     }
    150 
    151 }
    package Mini_xueshenguanliqi;
    
    
    public class Text01 {
        public static void main(String[] args) {
            Client c=new Client();
            Student arr[] = new Student[5];
            c.start();
        }
    }
  • 相关阅读:
    2009年职工象棋比赛 第七轮 五七炮对屏风马
    2009年职工象棋比赛 第一轮 顺炮直车对横车
    给文件起个好名字是多么的重要!
    职工象棋比赛 第十一轮 仙人指路
    2009年职工象棋比赛 第八轮 顺炮横车对直车
    2009年职工象棋比赛 第三轮 中炮对反宫马
    2009年职工象棋比赛 第二轮 中炮对单提马
    终于记住了这两个词:devour、devout
    2009年职工象棋比赛 第四轮 顺炮直车对横车
    2009年职工象棋比赛 第五轮 中炮对右三步虎
  • 原文地址:https://www.cnblogs.com/zhipeng-wang/p/11995227.html
Copyright © 2020-2023  润新知