作业
1. 五一假期注意安全,尽量减少外出,最好不要出省。
2. 复习,认真复习,好好复习
重点:
方法使用
数组使用和算法
面向对象
3. 总结
假期5天,完成一篇总结[最少是面向对象]
这里推荐使用Xmind思维导图
4. 尝试完成以下功能
实体类:
学生类:
id, 姓名,年龄,性别,成绩
需要使用数组保存学生信息
Student[] allStu
需要完成的方法
1. 根据学生的ID,找到对应的学生对象
2. 完成方法,添加新学生
3. 完成方法,删除指定ID的学生
4. 完成方法,展示数组中所有的学生信息
5. 根据学生成绩,完成降序排序
5. 假期查漏补缺,好好休息,我们期待线下相见!!!
public class Student implements StudentSort{
private int id;
private String name;
private String sex;
private int age;
private double score;
public Student() {
super();
}
public Student(int id, String name, String sex, int age, double score) {
super();
this.id = id;
this.name = name;
this.sex = sex;
this.age = age;
this.score = score;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getSex() {
return sex;
}
public int getAge() {
return age;
}
public double getScore() {
return score;
}
public void setId(int id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setSex(String sex) {
this.sex = sex;
}
public void setAge(int age) {
this.age = age;
}
public void setScore(double score) {
this.score = score;
}
//重写接口中的方法 按成绩排名
@Override
public boolean sort(Student student) {
if(this.score > student.score) {
return true;
}
return false;
}
/* //重写接口中的方法 按年龄排名
@Override
public boolean sort(Student o) {
if(this.age > o.age) {
return true;
}
return false;
}
*/
}
接口类
//定义比较方法 如果返回True 位置不变 否则交换位置
public interface StudentSort{
boolean sort(Student student);
}
首先现根据需求写出来学生类 然后将里面的属性私有化 并且实现接口的方法