50,528
社区成员
发帖
与我相关
我的任务
分享
package com.study;
public class Student {
private int no;
private String name;
private String sex;
private int age;
private double score1;
private double score2;
private double score3;
public double getAvgScore(){
return score1*score2*score3/3;
}
public Student(int no, String name, String sex, int age, double score1,
double score2, double score3) {
super();
this.no = no;
this.name = name;
this.sex = sex;
this.age = age;
this.score1 = score1;
this.score2 = score2;
this.score3 = score3;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getScore1() {
return score1;
}
public void setScore1(double score1) {
this.score1 = score1;
}
public double getScore2() {
return score2;
}
public void setScore2(double score2) {
this.score2 = score2;
}
public double getScore3() {
return score3;
}
public void setScore3(double score3) {
this.score3 = score3;
}
}
package com.study;
public class Test {
public static void main(String[] args) {
Student s1 = new Student(1,"张1","男",11,80,80,80);
Student s2 = new Student(2,"张2","男",12,78,66,90);
Student s3 = new Student(3,"张3","男",11,55,44,50);
Student s4 = new Student(4,"张4","男",13,88,92,99);
Student s5 = new Student(5,"张5","男",11,75,86,22);
Student[] ss = new Student[]{s1,s2,s3,s4,s5};
System.out.println("===========================================");
double maxScore1 = -1;
double maxScore2 = -1;
double maxScore3 = -1;
double minScore1 = Double.MAX_VALUE;
double minScore2 = Double.MAX_VALUE;
double minScore3 = Double.MAX_VALUE;
for(Student s : ss){
System.out.println(s.getName() + "的平均成绩为:" + s.getAvgScore());
if(maxScore1 <= s.getScore1()){
maxScore1 = s.getScore1();
}
if(minScore1 >= s.getScore1()){
minScore1 = s.getScore1();
}
if(maxScore2 <= s.getScore2()){
maxScore2 = s.getScore2();
}
if(minScore2 >= s.getScore2()){
minScore2 = s.getScore2();
}
if(maxScore3 <= s.getScore3()){
maxScore3 = s.getScore3();
}
if(minScore3 >= s.getScore3()){
minScore3 = s.getScore3();
}
}
System.out.println("===========================================");
System.out.println("score1最高分为:" + maxScore1);
System.out.println("score2最高分为:" + maxScore2);
System.out.println("score3最高分为:" + maxScore3);
System.out.println("===========================================");
System.out.println("score1最低分为:" + minScore1);
System.out.println("score2最低分为:" + minScore2);
System.out.println("score3最低分为:" + minScore3);
}
}