对象数组-学生管理系统
2021-11-27 本文已影响0人
柠栀5102
要求:搭建一个管理学生信息系统,具备查询、添加、修改、删除功能
第一步:搭建基本框架
定义一个最外层系统主菜单的方法

第二步:实现具体功能

1)查询学生
使用数组的高阶方法forEach()遍历真个数组,获取数组中每个元素,连接到字符串str,最后输出

2)添加学生
输入学生基本信息 学号是唯一不重复的,这里需要利用数组的高阶方法findIndex()返回对象数组中学号和输入学号一直的数组的下标,没有返回-1,如果没有重复输入其他信息,重复则执行while()语句,重新输入学号

3)修改学生
需要根据判断,该学生是否存在,存在继续执行do-while()语句,不存在stu获取的值为-1,执行while()语句
这里的stu获取的是这个对象数组中满足条件的数组

也可以返回在对象数组中满足条件的数组的下标

4)删除学生
这里的this指向的都是studentManager
