Question #265269

Create a class Calculator with two variables, a constructor with no parameter and



two functions for add and multiply. Add functionality for overloading sum and



multiply. Also call scientific functions using Math class (sine, cos, tan and power).



Create a class TestApp with a main function and create object of Calculator class to



call functions.

Expert's answer



package calculator;
class Calculator{
    private int first, second;
    public Calculator(){
        
    }
    
    public void sum(int f, int s){
       first = f;
       second = s;
        System.out.println("The sum is  "+ first+second);
    }
    
    public void sum(int f, int t, String m){
         first = f;
       second = t;
       m= "Multiplication of "+f+" and "+t+" is ";
        System.out.println(m +" "+f*t);
    }
    
}
public class TestApp  {


    
    public static void main(String[] args) {
      Calculator c = new Calculator();
      c.sum(10, 20);
      c.sum(20, 50, "");
    }
    
}

LATEST TUTORIALS
APPROVED BY CLIENTS