Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 那里';我的程序中有一个错误,错误是:需要类、接口或枚举。怎么办?_Java_Encapsulation - Fatal编程技术网

Java 那里';我的程序中有一个错误,错误是:需要类、接口或枚举。怎么办?

Java 那里';我的程序中有一个错误,错误是:需要类、接口或枚举。怎么办?,java,encapsulation,Java,Encapsulation,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 n

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;
    }
}
import java.util.Scanner;

class Student {
    public static void main(String args[]) {
        String name;
        String section;
        double one;
        double two;
        double three;
        double four;
        double genave;


        iLs a =  new iLs();
        Scanner input = new Scanner(System.in);


        a.setName = (input.nextLine());
        a.setSection = (input.nextLine());
        a.setOne = (input.nextLine());
        a.setTwo = (input.nextLine());
        a.setThree = (input.nextLine());
        a.setFour = (input.nextLine());
        a.setGenave = (input.nextLine());


        System.out.println("Name: " + a.getName());
        System.out.println("\nSection: " + a.getSection());
        System.out.println("\n1q: " + a.getOne());
        System.out.println("\n2q: " + a.getTwo());
        System.out.println("\n3q: " + a.getThree());
        System.out.println("\n4q: " + a.getFour());
        System.out.println("\nGeneral Average: " + a.getGenave());
    }
}
学生班:

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;
    }
}
import java.util.Scanner;

class Student {
    public static void main(String args[]) {
        String name;
        String section;
        double one;
        double two;
        double three;
        double four;
        double genave;


        iLs a =  new iLs();
        Scanner input = new Scanner(System.in);


        a.setName = (input.nextLine());
        a.setSection = (input.nextLine());
        a.setOne = (input.nextLine());
        a.setTwo = (input.nextLine());
        a.setThree = (input.nextLine());
        a.setFour = (input.nextLine());
        a.setGenave = (input.nextLine());


        System.out.println("Name: " + a.getName());
        System.out.println("\nSection: " + a.getSection());
        System.out.println("\n1q: " + a.getOne());
        System.out.println("\n2q: " + a.getTwo());
        System.out.println("\n3q: " + a.getThree());
        System.out.println("\n4q: " + a.getFour());
        System.out.println("\nGeneral Average: " + a.getGenave());
    }
}
一开始,我没有公共课,所以这个项目需要一个公共课。但当我这样做时,这就发生了,
错误:类、接口或枚举expecte
帮助


我不知道该怎么办,而且我对计算机编程是如此陌生。

假设上述内容来自单个文件,那么第一个问题是在第一个类定义之后有一个import语句


导入语句只能在类的开头出现一次

假设上述内容来自单个文件,那么第一个问题是在第一个类定义之后有一个import语句

导入语句只能在类的开头出现一次

你看过这个吗?

此外,在Student中,您试图实例化一个新的iLs,但没有匹配的构造函数签名。iLs中声明的唯一构造函数有7个参数,您试图调用默认构造函数(即没有参数)。只有在没有声明其他构造函数的情况下,Java才提供默认构造函数。一旦一个构造函数被声明,如果你想要一个默认的构造函数,你也必须声明它。

你看过这个吗?


此外,在Student中,您试图实例化一个新的iLs,但没有匹配的构造函数签名。iLs中声明的唯一构造函数有7个参数,您试图调用默认构造函数(即没有参数)。只有在没有声明其他构造函数的情况下,Java才提供默认构造函数。一旦一个构造函数被声明,如果你想要一个默认的构造函数,你也必须声明它。

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

iLs a =  new iLs();
然而,在这个iLS类中,没有一个构造函数只有零个参数

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

除了@ghostCat给出的答案外,学生代码还包括

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()在学生课堂上工作。更改ILS类的数据类型或转换值以匹配您的数据类型
Scanner.nextLine
将返回
string
,所有
one、two、three、four
都是
double

您给出的代码不是工作代码,因为您有一个参数化构造函数在ILS类中添加默认构造函数,使
ILS a=new ILS()在学生课堂上工作。更改ILS类的数据类型或转换值以匹配您的数据类型
Scanner.nextLine
将返回
string
,所有
1、2、3、4
都是
double

您有多少个文件?它们是如何命名的?和:检查你的问题的缩进。除此之外,我试图给出一个答案。如果合适的话:考虑接受答案。否则,请给我留言并改进您的问题例如,给出准确的错误信息,包括行号。请正确地缩进代码,这样很容易看到不同的部分。这次我已经为您做了。您有多少个文件?它们是如何命名的?和:检查您的缩进。除此之外,我试图给出答案。如果合适的话:考虑接受AN。回答。否则,请给我留言并改进您的问题(例如,通过给出包含行号的准确错误消息。请正确缩进您的代码,以便于查看不同的部分。这次我已经为您完成了。