import java.util.HashSet;
class Student{
int num;
String name;
double scores[]; //三门课程成绩
double aver; //平均成绩
public Student(){
this.scores=new double[3];
}
public Student(int num,String name,double score1,double score2,double score3){
this ();
this.setNumber(num);
this.setName(name);
this.setScores(double score1,double score2,double score3);//这里为什么编译错误?
this.aver=(this.scores[0]+this.scores[1]+this.scores[2])/3;
}
public void setNumber(int num){
this.num=num;
}
public void setName(String name){
this.name=name;
}
public void setScores(double score1,double score2,double score3){
this.scores[0]=score1;
this.scores[1]=score2;
this.scores[2]=score3;
}
public int getNumber(){
return num;
}
public String getName(){
return name;
}
public double[] getScores(){
return scores;
}
public double getAver(){
return aver;
}
public String toString(){
return "学号:"+this.num+"姓名:"+this.name+"\n"+"成绩————>"+"语文:"+this.scores[0]+"数学:"+this.scores[1]+"英语:"+this.scores[2]+"平均成绩:"+this.aver;
}
}
public class Test_11{
public static void main(String...args){
HashSet<Student> stu=new HashSet<Student>();
Student zhangsan=new Student("张三",18,78,85,92);
System.out.println(zhangsan);
}
}
这样的错误也会有。this.setScores(double score1,double score2,double score3);
改成
this.setScores(score1, score2, score3);