用java编写简单学生信息管理系统
import java.util.Scanner;import java.util.ArrayList;public class StudentManger { public static void main(String[] args) { Scanner in=new Scanner(System.in); ArrayList<Student> array=new ArrayList<>(); whi le(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("--------------------"); int a=in.nextInt(); switch (a) { case 1: addStudent(array);break; case 2: delete(array);break; case 3: xiugai(array);break; case 4: show(array);break; case 5: System.out.println("谢谢使用"); System.exit(0); } } } public static void addStudent(ArrayList<Student> array) { Scanner in=new Scanner(System.in); System.out.println("请输入学号:"); String id=in.nextLine(); System.out.println("请输入姓名:"); String name=in.nextLine(); System.out.println("请输入年龄:"); String age=in.nextLine(); System.out.println("请输入居住地:"); String place=in.nextLine(); Student s0=new Student(id,name,age,place); array.add(s0); } public static void xiugai(ArrayList<Student> array) { Scanner in=new Scanner(System.in); System.out.println("请输入要修改的学号:"); String id=in.nextLine(); for(int i=0;i<array.size();i++) { if(array.get(i).getId().equals(id)) { System.out.println("请输入学号:"); String date=in.nextLine(); System.out.println("请输入姓名:"); String name=in.nextLine(); System.out.println("请输入年龄:"); String age=in.nextLine(); System.out.println("请输入居住地:"); String place=in.nextLine(); Student s1=new Student(date,name,age,place); array.set(i,s1); } } } public static void delete(ArrayList<Student> array) { Scanner in=new Scanner(System.in); System.out.println("请输入要修改的学号:"); String id=in.nextLine(); for(int i=0;i<array.size();i++) { if(array.get(i).getId().equals(id)) { array.remove(i); } } } public static void show(ArrayList<Student> array) { for(int i=0;i<array.size();i++) { System.out.println("学号:"+array.get(i).getId()); System.out.println("姓名:"+array.get(i).getName()); System.out.println("年龄:"+array.get(i).getAge()); System.out.println("居住地:"+array.get(i).getPlace()); } }}class Student{ private String id; private String name; private String age; private String place; Student(){} Student(String id,String name,String age,String place) { this.name=name; this.age=age; this.id=id; this.place=place; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } public String getPlace() { return place; } public void setPlace(String place) { this.place = place; }}
|