[上]JAVA%e5%ad%a6%e4%b9%a0%e7%b3%bb%e5%88%97" title="查看更多关于 JAVA学习系列 的文章" target="_blank">JAVA学习系列197.学生管理系统项目_添加功能
视频
笔记
4.工具类_ArrayUtils
public class ArrayUtils {
private ArrayUtils(){
}
public static int findIndexById(Student[] students,int id,int count){
//遍历,查找
for (int i = 0; i < count; i++) {
if (id==students[i].getId()){
return i;
}
}
return -1;
}
}
5.添加功能_addStudent
private void addStudent() {
//1.键盘录入学生信息
System.out.println("请您输入学生学号:");
int id = sc.nextInt();
System.out.println("请您输入学生姓名:");
String name = sc.next();
System.out.println("请您输入学生年龄:");
int age = sc.nextInt();
System.out.println("请您输入学生性别:");
String sex = sc.next();
//2.将学生信息封装到Student对象中
Student student = new Student(id, name, age, sex);
//3.将封装好的Student对象放到students数组中
students[count] = student;
//4.count++记录存储了多少个对象
count++;
System.out.println("添加成功!!!");
}
