Answer to Question #265269 in Java | JSP | JSF for Shan

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.

1
Expert's answer
2021-11-13T02:02:19-0500


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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS