一开始自己写的学生管理系统被老师说了一通,说我写的学生管理系统是面向过程的,是c语言的逻辑,学java就应该用java的思想。
这个是我一开始写的面向过程的方法也就是错误示例:
package StudentManager;
import java.util.ArrayList;
import java.util.Scanner;
public class StudentManager {
public static void main(String[] args) {
ArrayList<Student> array = new ArrayList<>();
Scanner sc = new Scanner(System.in);
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.退出学生管理系统");
String line = sc.nextLine();
switch (line) {
case "1":
addStudent(array);
break;
case "2":
deleteStudent(array);
break;
case "3":
updateStudent(array);
break;
case "4":
findStudent(array);
break;
case "5":
System.exit(0);
System.out.println("感谢使用");
break;
default:
throw new IllegalStateException("Unexpected value: " + line);
}
}
}
private static void findStudent(ArrayList<Student> array) {
if (array.size() == 0) {
System.out.println("没有内容,请先添加");
} else {
System.out.println("姓名" + "\t" + "年龄" + "\t" + "学号" + "\t" + "地址");
for (int i = 0; i < array.size(); i++) {
Student s = array.get(i);
System.out.println(s.getName() + "\t" + s.getAge() + "\t" + s.getSid() + "\t" + s.getAddress());
}
}
}
private static void updateStudent(ArrayList<Student> array) {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("请输入要修改的学生学号");
String sid = sc.nextLine();
if (array.size()==0){
System.out.println("系统中没有内容,修改失败");
break;
}else {
int index = -1;
for (int i = 0; i < array.size(); i++) {
Student s = array.get(i);
if (s.getSid().equals(sid)) {
index = i