LEARN JAVA A Basic Calculator - not work


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

https://www.codecademy.com/courses/learn-java/projects/basic-calculator

<In what way does your code behave incorrectly? Include ALL error messages.>

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

```

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.”);
return 0;
} 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));

}

}

<do not remove the three backticks above>

#2

When we declare a constructor, we must use the following syntax:

public className(parameters,separated,by,commas){
  //Implementation of constructor.
  //What do we want done when it's called?
}

The syntax is NOT as follows:

public className(parameters);


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.