0

ILS Class:

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

Student Class:

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

At first, i don't have public class so the program demanded wants a public class. But when I do, this happened, error: class, interface, or enum expecte HELP!!!

I don't know what to do and I'm so new to Computer Programming.

user2004685
  • 9,548
  • 5
  • 37
  • 54
BLAHx
  • 1
  • How many files do you have? How are they named? And : check the indenting of your in question. – GhostCat Oct 05 '18 at 02:17
  • 2
    Beyond that, I tried to give an answer. If that fits: consider accepting the answer. Otherwise drop me a comment and improve your question (for example by giving the exact error message including line numbers. – GhostCat Oct 05 '18 at 02:20
  • Please indent your code properly so it's easy to see different sections. I have done it for you this time. – user2004685 Oct 05 '18 at 02:23

4 Answers4

2

In addition to the answer given by @ghostCat, the code of Student includes

iLs a =  new iLs();

however in this iLS class there is not a constructor with zero parameters only

public iLs(String name, String section, double one, double two, double three,
                                                  double four, double genave){
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64
0

Assuming that the above content is from a single file, then the very first problem is that there is an import statement after the first class definition.

Import statements can appear only once, in the beginning of a class.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
0

Have you looked at this? Compiler error: "class, interface, or enum expected"

Also, in Student, you are trying to instantiate a new iLs, but do not have a matching constructor signature. The only constructor declared in iLs takes 7 parameters, and you are trying to call a default constructor (i.e. no params). The default constructor is provided by Java only if there are no other constructors declared. As soon as a constructor is declared, if you want a default constructor, you must declare it as well.

John Camerin
  • 677
  • 5
  • 15
0

The code which you have given is not a working code, since you have a parameterized constructor add default constructor in your ILS class to make iLs a = new iLs(); work in Student class. Change the data types of ILS class or convert the values to match your datatypes. Scanner.nextLine will return string, all your one,two,three,four are double.

Nithyananth
  • 74
  • 10