Ask Question
9 October, 15:59

Assume the availability of an existing class, ICalculator, that models an integer arithmetic calculator and contains:an instance variable currentValue that stores the current int value of the calculatora getter method for the above instance variablemethods add, sub, mul, and divEach method in ICalculator receives an int argument and applies its operation to currentValue and returns the new value of currentValue. So, if currentValue has the value 8 and sub (6) is invoked then currentValue ends up with the value 2, and 2 is returned. So, you are to write the definition of a subclass, ICalculator1, based on ICalculator. The class ICalculator1 has one additional method, sign, that receives no arguments, and doesn't modify currentValue. Instead, it simply returns 1, 0 or - 1 depending on the whether currentValue is positive, zero, or negative respectively.

+1
Answers (1)
  1. 9 October, 16:18
    0
    Explanation to the approach and code given below

    Explanation:

    I am considering that you need only a defined subclass and not the working program.

    So given statement is,

    The class ICalculator has one additional method, sign, that receives no arguments, and doesn't modify currentValue. Instead, it simply returns 1, 0 or - 1 depending on the whether currentValue is positive, zero, or negative respectively.

    Here is the code:

    public class ICalculator1 extends ICalculator {

    public int sign () {

    if (currentValue! = 0) {

    return currentValue * - 1; }

    else {

    return 0;

    }

    }

    }

    or you can try this alternative soluton.

    public int sign () {

    int value = add (0); / / add 0 and return currentValue

    if (value > 0) return 1;

    else if (value < 0) return - 1;

    else return 0;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Assume the availability of an existing class, ICalculator, that models an integer arithmetic calculator and contains:an instance variable ...” 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