需求说明:定义学员类,存储学员信息(属性:姓名、成绩;方法:显示个人成绩)。编写修改成绩类,使用学员对象数组作为参数,实现学员成绩修改,条件为:如果学员成绩小于60,集体提高2分。最终输出修改成绩后每个学员的成绩.
package com.company.kgc.bean.base;
public class Hello3 {
String name;
double score;
_______________________________________________________________
public Hello3(String name, double score) {
this.name = name;
this.score = score;
}
}
package com.company.kgc.bean.base;
public class Hello2 {
public static void main(String[] args) {
Hello3 s1=new Hello3(name:"亏",score:24); //创建对象、赋值
Hello3 s2=new Hello3(name:"看",score:23);
Hello3 s3=new Hello3(name:"非",score:34);
Hello3[] s={s1,s2,s3}; //将姓名、成绩保存到数组中
for(Hello3 d:s){ //遍历数组
if(d.score<60){ //找到分数低于60的
for(Hello3 f:s){ //将数组中所有分数+2
f.score+=2;
}
}
}
for(Hello3 a:s){ //重新输出
System.out.println(a.name+"成绩是:"+a.score);
}
}
}