Answered! Assume the availability of an existing class , ICalculator, that models an integer arithmetic calculator and contains:…

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 calculator

a getter method for the above instance variable

methods  addsubmul, and div

Each method in ICalculator receives an int  argument and applies its operation to currentValue and returns the new value ofcurrentValue. So, if currentValue has the value 8 and sub(6) is invoked then currentValueends 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.

Expert Answer

 I am cosidering that you need only a defination of a subclass and not the working program.
So given statment is, 
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.

Here is the solutions.

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;
}
Still stressed from student homework?
Get quality assistance from academic writers!