12 errors Calculator project Modulo and main method


#1



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


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));
    }
  }
  }


#2

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));
}
}


#3

Seems to work now...........................................


#4

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