import java.util.*;import java.util.Calendar;public class Student { int id, Byear;double eng,math,com;public Student(int id, int Byear, double eng,double math,double com){ // 参数列表要这么改 this.id = id;this.Byear = Byear;this.eng = eng;this.math = math;this.c...
java编译报错:实际参数列表和形式参数列表长度不同
以下是我给你修改的代码,有注释的行是你需要改的。纯手写,求财富值!(下种子用...T_T)
import java.util.*;
import java.util.Calendar;
public class Student {
int id, Byear;
double eng,math,com;
public Student(int id, int Byear, double eng,double math,double com){ // 参数列表要这么改
this.id = id;
this.Byear = Byear;
this.eng = eng;
this.math = math;
this.com = com;
};
public int getId(){
return id;
}
public int getBYear(){
return Byear;
}
public double getEng(){
return eng;
}
public double getMath(){
return math;
}
public double getCom(){
return com;
}
public double getSum(){
return this.eng + this.math + this.com;
}
public int getAge(int Byear) throws Exception { //Byear 参数类型改为int
Calendar cal = Calendar.getInstance();
if ( cal.get(Calendar.YEAR) < Byear) { //把当前年份和输入年份比较
throw new IllegalArgumentException(
"The birthYear is before Now.It's unbelievable!");
}
int yearNow = cal.get(Calendar.YEAR); //得到当前年份
// cal.setTime(Byear); 不要了
// int yearBirth = cal.get(Calendar.YEAR); 不要了
int age = yearNow - Byear; //相减得到年龄
return age;
}
public static void main(String[] args){
Date NowYear = new Date(); // 输出当前时间
System.out.println(NowYear);
Student stu = new Student(1054,1993,78,84,90); //这时按照你的构造函数实例化Student类
System.out.println("总成绩:"+stu.getSum());
System.out.println("年龄:"+stu.getAge());
//System.out.println(stu.toString()); 你没有@Override toString()函数,别这么写
}
}2013-12-29
public int getAge(Date Byear) 这个方法需要一个Date类型的参数,但你在main方法里调用的时候,stu.getAge();是这样调用的,并没有给他一个Date类型的参数,所以报错2013-12-29
stu.getAge(); 这个方法在使用的时候要传一个Date类型的参数,你没传 ,所以出错
public int getAge(Date Byear) throws Exception2013-12-29