Basic Calculator error

Hey there,

I’m working on https://www.codecademy.com/courses/learn-java/projects/basic-calculator this calculator project and I do not understand the error I’m getting. Please help?!
My code:
public class Calculator{

public Calculator(){
System.out.println(“I’m a 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(“5+7=”, myCalculator.add(5,7));
}

The error message:
Calculator.java:22: error: class, interface, or enum expected
public static void main(String args){
^
Calculator.java:24: error: class, interface, or enum expected
System.out.println(“5+7=”, myCalculator.add(5,7));
^
Calculator.java:25: error: class, interface, or enum expected
};
^
3 errors

I’m not all done yet with this project, but this error has me so confused, I’m not sure if I’m able to finish.
Thanks for your help in advance!

Hi, welcome :slight_smile: ,

This code is has 2 main errors. One error hides the other.

In java, main methods live inside classes (unlike C++ main functions). Right now your structure is thus:

public class Calculator {
    //class definition
}

public static void main(String[] args) {
    //main method definition
}

However it should be

public class Calculator {
    //class definition
    public static void main(String[] args) {
    //main method definition
    }
}

The other error is you the way you’re using the println() method. This takes a specific type as an argument (like int, string, bool, etc.). The method is not going to know what to do with
println(value1, value2).
Think about how you can concatenate the two things you want printed.

That helped, thank you so much :slight_smile: