为了账号安全,请及时绑定邮箱和手机立即绑定

我的程序中有一个错误,提示错误:类、接口或枚举预期。该怎么办?

我的程序中有一个错误,提示错误:类、接口或枚举预期。该怎么办?

互换的青春 2021-10-28 09:37:39
ILS 等级:import java.util.Scanner;class iLs {    private String name;    private String section;    private double one;    private double two;    private double three;    private double four;    private double genave;    public iLs(String name, String section, double one, double two, double three, double four, double genave){        this.name =  name;        this.section = section;        this.one = one;        this.two = two;        this.three = three;        this.four = four;        this.genave = genave;    }    public void setName(String name){        this.name = name;    }    public void setSection(String section){        this.section = section;    }    public void setOne(String one){        this.one = one;    }    public void setTwo(String two){        this.two = two;    }    public void setThree(String three){        this.three = three;    }    public void setFour(String four){        this.four = four;    }    public void setGenave(String genave){        this.genave = genave;    }    public String getName(){        return name;    }    public String getSection(){        return section;    }    public double getOne(){        return one;    }     public double getTwo(){        return two;    }    public double getThree(){        return three;    }    public double getFour(){        return four;    }    public double getGenave(){        return genave;    }}起初,我没有公开课,所以要求的程序需要公开课。但是当我这样做时,这发生了,error: class, interface, or enum expecte帮助!!!我不知道该怎么做,而且我对计算机编程还很陌生。
查看完整描述

3 回答

?
一只斗牛犬

TA贡献1784条经验 获得超2个赞

除了@ghostCat给出的答案,Student的代码还包括

iLs a =  new iLs();

但是在这个 iLS 类中,没有只有零参数的构造函数

public iLs(String name, String section, double one, double two, double three,
                                                  double four, double genave){


查看完整回答
反对 回复 2021-10-28
?
达令说

TA贡献1821条经验 获得超6个赞

您提供的代码不是工作代码,因为您在 ILS 类中有一个参数化构造函数添加默认构造函数,以便iLs a =  new iLs();在 Student 类中工作。更改 ILS 类的数据类型或转换值以匹配您的数据类型。Scanner.nextLine会回来的string,都是你one,two,three,fourdouble


查看完整回答
反对 回复 2021-10-28
?
料青山看我应如是

TA贡献1772条经验 获得超8个赞

在 Student 中,您尝试实例化一个新的 iL,但没有匹配的构造函数签名。iLs 中声明的唯一构造函数需要 7 个参数,并且您正在尝试调用默认构造函数(即没有参数)。仅当没有声明其他构造函数时,Java 才提供默认构造函数。一旦声明了一个构造函数,如果你想要一个默认的构造函数,你也必须声明它。

查看完整回答
反对 回复 2021-10-28
  • 3 回答
  • 0 关注
  • 149 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信