Stuck in Basic Calculator (java)/ error: class, interface, or enum expected

Hi, I’m new and I’m also not a native speaker in English.

I am stuck in this task with the following error: class, interface, or enum expected.

That’s my code:

Would be great to get help!

You forgot curly braces after your constructor which should be

public Calculator() {} 

And I think you need to consider zero-division error in the division and modulo function.
Using an if… else statement will do the trick! Hope this helps!

The class interface or enum expected error is a compile-time error in Java which arises due to curly braces. Typically, this error occurs when there is an additional curly brace at the end of the program.

I got pretty much the same error, plus an additional one for each method call. I had not forgot the {} at the constructor, but apparently I had them in the wrong place. My code was first this;

public class Calculator{

  public Calculator() {}

  public int add(int a, int b) {
    return a + b;
  }

  public int subtract(int a, int b) {
    return a - b;
  }

  public int multiply(int a, int b) {
    return a * b;
  }

  public int divide(int a, int b) {
    return a / b;
  }

  public int modulo(int a, int b) {
    return a % b;
  }
}
public static void main (String[] args) {

  Calculator myCalculator = new Calculator();

  System.out.println(myCalculator.add(5,7));
  System.out.println(myCalculator.subtract(45,11));
  System.out.println(myCalculator.multiply(5,7));
  System.out.println(myCalculator.divide(47,3));
  System.out.println(myCalculator.modulo(47,3));
}

i.e. I closed the class definition before the Main method. Here I got the errors, starting with the same one that OP got.
I changed the code, moving the last } before the Main method from line 26 to the last line, thus including the Main method in the definition of the Calculator class. This runs as expected.

My question: Why does the Main method need to be part of the class definition?
I learned that the Main method is always the entry point for any Java program (correct?), and when running one, the Main method should be the first thing that is encountered (correct?) while classes that are needed would typically be defined in a separate file each and imported to main.java. In that case, the Main Method is not part of any custom-made class (correct?).
Also, it can run on its own when not inside a class - so why can’t it when we define a class further up in the file?