Ask Question
31 July, 05:49

Write the class Calculator including: a function called addthat takes two parameters containing double values and returns their sum a function called subtractthat takes two parameters containing double values and returns their difference (subtract the second from the first) a function called multiply that takes two parameters containing double values and returns their product a function called divide that takes two parameters containing double values and returns the value of the first divided by the second. If the second number is a zero, do not divide, and return "You can't divide by zero!"

+2
Answers (1)
  1. 31 July, 06:04
    0
    public class Calculator {

    public double add (int a, int b) {

    return a+b;

    }

    public double substract (int a, int b) {

    return a-b;

    }

    public double multiply (int a, int b) {

    return a*b;

    }

    public double divide (int a, int b) {

    if (b>0) {

    return a/b;

    }

    else{

    System. out. println ("Cannot divide by zero");

    }

    return - 1;

    }

    }

    Explanation:

    Using Java Programming Language, the class Calculator is created. There are no fields (Instance variables) and no constructors since these are not required by the question. Four methods (functions) are created: add, substract, multiply and divide as specified in the question. Note the use of the if statement in the divide () to handle case of illegal division (by 0)
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write the class Calculator including: a function called addthat takes two parameters containing double values and returns their sum a ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers