Basic Calculator (OOP)


#1

Codecademy whats up, i'm back again with a small problem.

I've been going over & over (restarting the project) because
OOP lesson has been a bit tough for me. I have to say now
I am understanding it ALOT better thanks to the restart task
button. Anyways i've written this Basic Calculator code &
i'm not understanding where i'm going wrong or why. Any help
would be appreciated, thanks in advance!

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) {
  if (b == 0) {
    System.out.println("Error! Dividing by zero is not allowed.");
  return 0;
  }
else { 
  return a / b;
}
}
  
  public int modulo(int a, int b) {
    if (b == 0) {
      System.out.println("Error! Dividing by zero is not allowed.");
    } 
    else {
      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));
    }
  }

Edit: Here is the error message I forgot to mention.

Calculator.java:2: error: missing method body, or declare abstract
public Calculator(); {
^
1 error


#2

Hey @kodeman89! So your problem is when you were starting out your constructor you added a unnecesary semiconlon after your parantheis down below. Remove that. And just saying Java is the best ! :smile:

public class Calculator {
  public Calculator(); {

}

#3

Ah Okay, lol I knew it couldn't be much I couldn't tell
you how many times i've re-read the code & didn't
notice lol. Thanks again amanuel2! :sweat_smile: