package 复习试炼场;
import java.util.ArrayList;
import java.util.Scanner;
public class Student {
public static void main(String[] args) {
ArrayList<StudentDemo> array=new ArrayList<StudentDemo>();
while (true){
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("请输入你的选择:");
Scanner sc=new Scanner(System.in);
String line = sc.nextLine();
switch (line){
case "1":
// System.out.println("添加成功");
addStudent(array);
break;
case "2":
System.out.println("删除成功");
break;
case "3":
findStudent(array);
System.out.println("查看成功");
break;
case "4":
System.out.println("修改成功");
break;
case "5":
System.out.println("退出学生管理系统");
System.exit(0);
}
}
}
public static void addStudent(ArrayList<StudentDemo> array){
Scanner sc=new Scanner(System.in);
System.out.println("请输入你的学号:");
String sid = sc.nextLine();
System.out.println("请输入你的姓名:");
String name = sc.nextLine();
System.out.println("请输入你的年龄:");
String age = sc.nextLine();
System.out.println("请输入你的居住地:");
String adress = sc.nextLine();
StudentDemo s=new StudentDemo();
s.setSid(sid);
s.setName(name);
s.setAge(age);
s.setAdress(adress);
}
public static void findStudent(ArrayList<StudentDemo> array){
for(int i=0;i<array.size();i++){
System.out.println("学号\t姓名\t年龄\t居住地");
StudentDemo s=array.get(i);
System.out.println(s.getSid()+"\t"+s.getName()+"\t"+s.getAge()+"岁"+s.getAdress());
}
}
}
package 复习试炼场;
public class StudentDemo {
private String sid;
private String name;
private String age;
private String adress;
public StudentDemo() {
}
public StudentDemo(String sid, String name, String age, String adress) {
this.sid = sid;
this.name = name;
this.age = age;
this.adress = adress;
}
public String getSid() {
return sid;
}
public void setSid(String sid) {
this.sid = sid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getAdress() {
return adress;
}
public void setAdress(String adress) {
this.adress = adress;
}
}