12 errors Calculator project Modulo and main method

<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:25: error: illegal start of expression
public int modulo(int a, int b){
^
Calculator.java:25: error: ‘;’ expected
public int modulo(int a, int b){
^
Calculator.java:25: error: expected
public int modulo(int a, int b){
^
Calculator.java:25: error: not a statement
public int modulo(int a, int b){
^
Calculator.java:25: error: ‘;’ expected
public int modulo(int a, int b){
^
Calculator.java:32: error: illegal start of expression
public static void main(String args){
^
Calculator.java:32: error: illegal start of expression
public static void main(String args){
^
Calculator.java:32: error: ‘;’ expected
public static void main(String args){
^
Calculator.java:32: error: ‘.class’ expected
public static void main(String args){
^
Calculator.java:32: error: ‘;’ expected
public static void main(String args){
^
Calculator.java:33: error: ‘(’ or ‘[’ expected
Calulator myCalculator = new myCalculator;
^
Calculator.java:38: error: reached end of file while parsing
}
^
12 errors

```

public class Calculator{
public Calculator(){

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

public int substract(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){
Calulator myCalculator = new myCalculator;
System.out.println(myCalulator.add(5,7));
System.out.println(myCalulator.substract(45,11));
}
}
}

<do not remove the three backticks above>

public class Calculator{
public Calculator(){

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

public int substract(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.substract(45,11));
}
}

Seems to work now…

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