有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java我的程序中有一个错误,表示错误:需要类、接口或枚举。怎么办?

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());
    }
}

一开始,我没有公共课,所以这个项目需要一个公共课。但当我这么做的时候,事情发生了,error: class, interface, or enum expecte救命

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


共 (3) 个答案

  1. # 1 楼答案

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

    iLs a =  new iLs();
    

    然而,在这个iLS类中,没有一个构造函数只有零个参数

    public iLs(String name, String section, double one, double two, double three,
                                                      double four, double genave){
    
  2. # 2 楼答案

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

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

  3. # 3 楼答案

    您给出的代码不是工作代码,因为您在ILS类中有一个参数化构造函数add default constructor,使iLs a = new iLs();在学生类中工作。更改ILS类的数据类型或转换值以匹配您的数据类型Scanner.nextLine将返回string,您所有的one,two,three,four都是double