[上]JAVA学习系列197.学生管理系统项目_添加功能
视频
[vbilibili]【尚硅谷2024最新JAVA入门视频教程(上部)JAVA零基础入门教程】 https://www.bilibili.com/video/BV1YT4y1H7YM/?p=197&share_source=copy_web&vd_source=85f561e7442caa320f4a23b57edee129[/vbilibili]
笔记
3.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;
}
}
3.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("添加成功!!!");
}
