public class Student {
String name;
String ID;
int age;
String class1;
@Override
public String toString() {
return class1 +"\t"+ ID+ "\t" + name +"\t"+ age;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((ID == null) ? 0 : ID.hashCode());
result = prime * result + age;
result = prime * result + ((class1 == null) ? 0 : class1.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Student other = (Student) obj;
if (ID == null) {
if (other.ID != null)
return false;
} else if (!ID.equals(other.ID))
return false;
if (age != other.age)
return false;
if (class1 == null) {
if (other.class1 != null)
return false;
} else if (!class1.equals(other.class1))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
public class StudentManagementSystem {
public static void main(String[] args) {
//定义学生管理系统,实现功能
// 1.查询学生信息
// 2.添加学生信息
// 3.删除学生信息
// 4.修改学生信息
// 5.退出系统
//创建集合
ArrayList<Student> list = new ArrayList<Student>();
init(list);
while(true){
int x = jieShou();
switch (x) {
case 1:
chaXun(list);
break;
case 2:
addStudent(list);
break;
case 3:
revemoStudent(list);
break;
case 4:
xiuGaiStudent(list);
break;
case 5:
exit();
break;
default:
System.out.println("你的输入有误,请重新输入!");
break;
}
list.add(s);
}
//3.删除学生信息
public static void revemoStudent(ArrayList<Student> list){
//键盘录入
Scanner sc = new Scanner(System.in);
System.out.println("请输入你要删除的学生姓名:");
String name = sc.next();
//for遍历
for (int i = 0; i < list.size(); i++) {
Student s = list.get(i);