zoukankan      html  css  js  c++  java
  • 初学java 学生管理系统——v0001版本

    java刚开始学了几天,写了第一个复杂一点点的小程序

    发出来记录一下学习进度

    贴一下程序基本功能

    1 添加学生
    2 删除学生
    3 修改学生
    4 查看学生

     

    所以就先这样写一个主菜单

      这个方法就单纯为了在控制台打印一个菜单 其实可以写在main方法中的……然而我单纯嫌它占位置,影响我查看后面的switch语句

    1  public static void showMenu() {
    2         System.out.println("--------欢迎来到学生管理系统--------");
    3         System.out.println("1 添加学生");
    4         System.out.println("2 删除学生");
    5         System.out.println("3 修改学生");
    6         System.out.println("4 查看学生");
    7         System.out.println("5 退出");
    8         System.out.println("---------------------------------");
    9  }

    由于是个学生管理系统,因此还需要创建个学生类

    包含基本的几个字段 学号 姓名 年龄 生日

    并且提供基本的构造方法以及get/set方法

     1 public class Student {
     2     private String sid;     // 学号
     3     private String name;    // 姓名
     4     private int age;        // 年龄
     5     private String birthday; // 生日
     6     
     7     public Student() {
     8     }
     9     
    10     public Student(String sid, String name, int age, String birthday) {
    11         this.sid = sid;
    12         this.name = name;
    13         this.age = age;
    14         this.birthday = birthday;
    15     }
    16     
    17     public String getSid() {
    18         return sid;
    19     }
    20     
    21     public void setSid(String sid) {
    22         this.sid = sid;
    23     }
    24     
    25     public String getName() {
    26         return name;
    27     }
    28     
    29     public void setName(String name) {
    30         this.name = name;
    31     }
    32     
    33     public int getAge() {
    34         return age;
    35     }
    36     
    37     public void setAge(int age) {
    38         this.age = age;
    39     }
    40     
    41     public String getBirthday() {
    42         return birthday;
    43     }
    44     
    45     public void setBirthday(String birthday) {
    46         this.birthday = birthday;
    47     }
    48 }
    class Student

    接下来先写main方法

      由于学生的个数不可知,并且是个动态的增删的

      所以选择使用集合ArrayList来存储 通过泛型保证集合数据的类型一致

      之后通过while的死循环保证程序不停止 但是还是要留一个结束程序的选项

      因为被switch包裹 所以break需要增加循环标号 跳出while从而结束程序

      通过switch语句 来对用户的输入进行相应的方法调用 这里暂时先用输出语句表示方法被调用

     1     public static void main(String[] args) {
     2         // 接收控制台输入
     3         Scanner sc = new Scanner(System.in);
     4         // 存储学生对象
     5         ArrayList<Student> list = new ArrayList<>();
     6         lo:
     7         while (true) {
     8             // 显示主菜单
     9             showMenu();
    10             // 提示用户输入
    11             System.out.println("请输入您的选择:");
    12             String choice = sc.next();
    13             
    14             switch (choice) {
    15                 case "1":
    16                     System.out.println("添加学生");
    17                     break;
    18                 case "2":
    19                     System.out.println("删除学生");
    20                     break;
    21                 case "3":
    22                     System.out.println("修改学生");
    23                     break;
    24                 case "4":
    25                     System.out.println("查看学生");
    26                     break;
    27                 case "5":
    28                     System.out.println("感谢您的使用");
    29                     break lo;
    30                 default:
    31                     System.out.println("您的输入有误");
    32                     break;
    33             }
    34         }
    35     }

    这一版本暂且先到这里,先画个界面出来

    后续更新再继续写各个方法的实现

  • 相关阅读:
    232. Implement Queue using Stacks
    231. Power of Two
    n&(n-1)位运算的妙用
    230. Kth Smallest Element in a BST
    关于UNIX的exec函数
    Go语言的各种Print函数
    Go语言的接口interface、struct和组合、继承
    Go语言知识点笔记
    Ubuntu自定义终端窗口位置
    Python的类变量和成员变量、类静态方法和类成员方法
  • 原文地址:https://www.cnblogs.com/yao-xi/p/13742036.html
Copyright © 2011-2022 走看看