Help making the calculator?


#1

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

I am having several errors with my calculator, and I can’t figure out how to fix them. Apparently the errors are on line 32 and 46, 32 being the start of the modulo method and 46 being when I create my main method. My code is below, any help would be greatly appreciated.

public class Calculator {
  public Calculator() {
    
  }
  
  public int add(int a, int b) {
    
    return a+b;
    
  }
  
  public int subtract(int a, int b) {
    
    return c - d;
  }
  public int multiply(int a, int b) {
  
    return e * f;
    
  }
  public int divide(int a, int b) {
   
    if (b==0)
    {
      System.out.println("Error! Diving 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! Diving 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));
      
      
    }
      
  }
  
}

#2

All of your parameters are a and b, but only one method uses them correctly. Use a and b consistently in all the methods so they matchthe parameters.

Also this may be of some importance…

https://stackoverflow.com/questions/3346764/should-java-methods-be-static-by-default