java:学生信息系统
一、所用知识
将使用if、switch循环语句、类、封装、集合等,同时了解随机数的产生、键盘世家的处理等。
二、使用步骤
1.编写实体类
(1)创建com.itheima.domain包
(2)创建Student类
(3)添加“构造方法”和“需要重写的方法”
package com.itheima.domain;
public class Student{
private String sid;//学号
private String name;//姓名
private int age;//年龄
private String birthday;//生日
public Student(){
}
public Student (String sid,String name,int age,String birthday){
this.sid=sid;
this.name=name;
this.age=age;
this.birthday=birthday;
}
public String getSid(){
return sid;
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public int getAge(){
return age;
}
public void setAge(int age){
this.age=age;
}
public String getBirthday(){
return birthday;
}
public void setBirthday(String birthday){
this.birthday=birthday;
}
}
2.添加主体代码
代码如下:
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
//创建集合容器对象
ArrayList<Student> list = new ArrayList<>();
lo:
while (ture){
//1.搭建主界面菜单
System.out.println("----------欢迎来到学生管理系统---------");
System.out.println("1 添加学生");
System.out.println("2 删除学生");
System.out.println("3 修改学生");
System.out.println("4 查看学生");
System.out.println("5 退出");
System.out.println("请输入您的选择");
String choice = sc.next();
switch (choice){
case "1":
//System.out.println("添加学生");
addStudent(list);
break;
case "2":
//System.out.println("删除学生");
deletsStudent(list);
break;
case "3":
//System.out.println("修改学生");
updateStudent(list);
break;
case "4":
//System.out.println("感谢您的使用");
break lo;
default:
System.out.println("您的输入有误");
break;
}
}
}
效果如下:
3.添加学生代码
//添加学生的方法
public static void addStudent(ArrayList<Student> list){
Scanner sc=new Scanner(System.in);
//1.给出录入的提示信息
String sid;
while(ture