Basic Calculator Help

I’m currently working on the Basic Calculator but am a bit stuck. After saving what I’d entered, I received the following error:

Calculator.java:30: error: reached end of file while parsing

  • } *
  • ^*
    1 error

From what I’ve found on the error, it’s missing the ‘}’ somewhere, but I can’t quite figure out where at a quick glance. Would anyone mind taking a look with some fresh eyes? I’ll come back to it after work but thought I’d see if anyone has input.

Here’s what I have so far:

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(4,7)); System.out.println(myCalculator.subtract(45,11));
}

Hello, @nmarino5. Welcome to the forum. If you could follow the instructions in the post pasted below to format your code, it will be much, much easier for someone to help you.

I believe I spotted your issue (see comment above), but formatting your code for future posts will be quite helpful. Happy coding!

2 Likes

Sorry about that! I haven’t used the forum before and should have taken a closer look at the formatting options before posting :grimacing:

Thank you for the heads up on formatting!

2 Likes

Thank you so much for being an additional pair of eyes for me! I appreciate the help!

1 Like

You’re very welcome!

I have to apologize for misleading you. I’m not really very proficient with Java yet, but have a bit of experience with C# which is quite similar. Similar, but not exactly the same. The location of the missing brace would go where I had indicated in a C# program, but in Java, the main() method resides inside the scope of the class, so the missing brace should come after the closing brace for the main() method not before the main() method as I had indicated. Sorry about that. I will edit my earlier post so as not to mislead future readers. I did also notice an issue with this line:

calculator myCalculator = new Calculator(); //calculator should be capitalized

Happy coding!

1 Like

No worries, I figured I’d just come back and take a look again today when the original bracket didn’t work and it now runs. Thanks so much, I appreciate your help!

1 Like