1.

Write a program to create a class calculator with the following methods: - i) Sum(int x, int y)- accept two argument and return their sum as integer. ii) Diff(double x, int y)- accept two argument and return their difference as double. iii) Prod(float x, double y)- accept two argument and return their product as double.​

Answer»

en problem is solved using language - Java.public class Calculator{    int sum(int x,int y){        RETURN x+y;    }    double DIFF(double x,int y){        return x-y;    }    double Prod(float x,double y){        return x*y;    }    public static void main(STRING args[]){        Calculator object=new Calculator();        System.out.println(object.sum(2,3));        System.out.println(object.Diff(3.0,2));        System.out.println(object.Prod(2.0f,3.0));    } }Here, we have created three functions - Sum(), Diff() and Prod() which calculates the sum, difference and product of two numbers. The functions are then CALLED inside main() method after creating object.See attachment for OUTPUT.



Discussion

No Comment Found