java编译报错:实际参数列表和形式参数列表长度不同

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
mengvlog 阅读 8 次 更新于 2025-07-20 19:38:58 我来答关注问题0
  • 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...

  •  百度网友da60272 java给按钮引用图片时出现了(实际参数列表和形式参数列表长度不同)

    你的程序有两处是需要改的:1.contentPane.add(icon1);//将按钮加到面板上 这句,面板添加的应该是lbcon1。。所以应该为:contentPane.add(lbcon1);2.JLabel lbcon1=new JLabel("我的第一个程序~喵",icon1,SwingConstants.TOP);//文字在图片的上面。。。这句,SwingConstants.TOP这里有问题。

  • anonymous Java抽象类创建对象时报错:实际参数列表和形式参数列表长度不同。请大佬们解释一下?

    你的Manager类的构造方法是有参数的啊,你在new对象的时候,没有给构造方法参数,编译自然是不通过的

  •  Cool__Wu Java代码bug求助,实际参数列表与形式参数列表长度不同?

    实际参数列表必须和形式参数列表保持一致。第三张图中定义的get方法是不需要参数的,所以调用是不可以传参数。如果有帮助到你,请点击采纳。

  • Cylinder缺少一个空参构造函数 public Cylinder() { super();} 因为在Ringcylinder的构造函数中会默认调用 super();而Cylinder不存在该构造函数所以报错。

檬味博客在线解答立即免费咨询

Java相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部