public class Test {
public static void main(String[] args) {
Student s1 = new Student("小猫",60,70,80);
Student s2 = new Student("大猫",80,90,50);
Student s3 = new Student("大花",79,90,50);
s1.He(79,90,50);
System.out.println(s1.Name()+";总和:"+s1.Sum()+"平均分:"+s1.Score());
System.out.println(s2.Name()+";总和:"+s2.Sum()+"平均分:"+s2.Score());
System.out.println(s3.Name()+";总和:"+s3.Sum()+"平均分:"+s3.Score());
}
}
-------------------------------------------
package HomeWork;
//变量名不能大写,常量的,方法名要大写
public class Student {
private String name ; //姓名
private int language ; //语文
private int mathematics ; //数学
private int english ; //
public Student(String name1, int language1, int mathematics1, int english1) {//构造函数
super();
this.name = name1;
language = language1;
mathematics = mathematics1;
english = english1;
}
public int Sum(){
return language+mathematics+english; //求总分
}
public int Score(){
return (language+mathematics+english)/3; //求平均分:总分除以3个科目
}
public void He(int language2, int mathematics2, int english2){//求他们中最高分数的人
int[] sum1={language2,mathematics2,english2};
int he=language2>mathematics2?(language2>english2?language2:english2):(mathematics2>english2?
mathematics2:english2);
System.out.println(he);
/*for(int i=0;i<sum1.length;i++){
System.out.println(sum1[i]);//把他们的成绩存放到数组中,通过元素把三个数通过比较得出结果
}*/
}
public String Name(){
return name;
}
}