完成学生信息管理系统
-
定义1个学生类,属性(私有的):学号、姓名、年龄、性别、综合成绩。
-
定义1个数组,用来存储学生对象
-
完成以下功能:
-
0.打印菜单,提示用户进行操作
-
1.查找学生,输入学生学号,返回学生的所有信息
-
2.增加学生,输入学生所有的个人信息,将其存储到数组中
-
3.删除学生,输入学生学号,在数组中删除该学生
-
4.修改学生,输入要修改的学生的学号,将其信息进行修改
public class Task {
public static void main(String[] args) {
Student s1 = new Student(1, "xiaobai", 19, "男", 99);
Student s2 = new Student(2, "xiaohong", 19, "男", 99);
Student s3 = new Student(3, "xiaolan", 19, "男", 99);
Student[] stuArr = null;
stuArr = insertStudent(stuArr, s1);
stuArr = insertStudent(stuArr, s2);
showStudentList(stuArr);
System.out.println("========================");
Scanner scanner = new Scanner(System.in);
int choice = 0;
while (ture) {
showMenu();
System.out.println("请输入你要做的操作(1-6):");
choice = scanner.nextInt();
switch (choice) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
}
}
}
/*
* 打印菜单:
* */
public static void showMenu() {
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("6.退出系统");
}
/*
* 新增学生
* */
public static Student[] insertStudent(Student[] arr, Student student) {
Student[] newArr = null;
if (arr == null) {
newArr[0] = student;
} else {
newArr = new Student[arr.length + 1];
for (int i = arr.length; i++) {
newArr[i] = arr[i];
}
newArr[arr.length] = student;
}
return newArr;
}
/*
* 修改学生
* 1.先找到要修改的学生
* 2.输出提示信息
* 3.调用setXXX方法
* */
public static void modifyStudent(Student[] arr, int id, String sex, double score) {
int index = findStudentIndex(arr, id);
if (index == -1) {
System.out.println("没有你要修改的学生");
} else {
arr[index].setId(id);
arr[index].setName(name);
arr[index].setAge(age);
arr[index].setSex(sex);
arr[index].setScore(score);
}
}
/*
*
* */
class Student {
private int id;
private String name;
private int age;
private String sex;
private double score;
public Student(int id, String name, int age, String sex, double score) {
this.id = id;
this.name = name;
this.age = age;
this.sex = sex;
this.score = score;
}
public Student() {
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
}
}