public class Student {
private String name;
private int chinese;
private int math;
public Student() {
}
public Student(String name, int chinese, int math) {
this.name = name;
this.chinese = chinese;
this.math = math;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getChinese() {
return chinese;
}
public void setChinese(int chinese) {
this.chinese = chinese;
}
public int getMath() {
return math;
}
public void setMath(int math) {
this.math = math;
}
public void show(){
System.out.println(name+"的语文成绩:"+chinese+",数学成绩:"+math+",总成绩:"+(chinese+math));
}
}
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
Student s1 = new Student("邓超",88,99);
Student s2 = new Student("baby",85,78);
Student s3 = new Student("邓超",86,50);
ArrayList<Student> array = new ArrayList<>();
array.add(s1);
array.add(s2);
array.add(s3);
ArrayList<Student> array1=getSum(array);
for (int i = 0; i < array1.size(); i++) {
array.get(i).show();
}
}
public static ArrayList<Student> getSum(ArrayList<Student> list){
ArrayList<Student> array1 = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
Student stu=list.get(i);
int chinese=stu.getChinese();
int math=stu.getMath();
if(chinese+math>160){
array1.add(stu);
}
}
return array1;
}
}
|
|