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

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帮助!!!

我不知道该怎么做,而且我对计算机编程还很陌生。


互换的青春
浏览 151回答 3
3回答

一只斗牛犬

除了@ghostCat给出的答案,Student的代码还包括iLs a =  new iLs();但是在这个 iLS 类中,没有只有零参数的构造函数public iLs(String name, String section, double one, double two, double three,                                                   double four, double genave){

达令说

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

料青山看我应如是

在 Student 中,您尝试实例化一个新的 iL,但没有匹配的构造函数签名。iLs 中声明的唯一构造函数需要 7 个参数,并且您正在尝试调用默认构造函数(即没有参数)。仅当没有声明其他构造函数时,Java 才提供默认构造函数。一旦声明了一个构造函数,如果你想要一个默认的构造函数,你也必须声明它。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java