1.2.5 修改信息方法的编写
//修改信息
public static void setStudent(ArrayList<Student> str) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入要修改的学生学号:");
String id = sc.nextLine();
if (str.size() == 0) {
System.out.println("对不起,当前学生管理系统无任何信息");
return;
}else {
int index = -1;
for (int i = 0; i < str.size(); i++) {
if (str.get(i).getId().equals(id) ) {
index = i;
}
}
if (index == -1) {
System.out.println("对不起,你要修改的学生学号不存在,请重新选择:");
}else {
System.out.println("请输入学生的姓名:");
String name = sc.nextLine();
System.out.println("请输入学生的年龄:");
String age = sc.nextLine();
System.out.println("请输入学生的地址:");
String address = sc.nextLine();
Student s = new Student(id, name, age, address);
str.set(index, s);