requirement
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 calculatormethods add, sub, mul, and div
Each 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.
code:
1 public class ICalculator1 extends ICalculator {
2 public int getCurrentValue() {return currentValue;} //**did not need this line**
3
4 int sign() {
5 if(currentValue > -1) return 0; //changed to**int val = add(0);**
6 else if(currentValue < 0) return -1; //changed to **if (val > 0) return 1;**
7 else return 1; //changed to **else if (val < 0) return -1;**
8 }}
error message:
ICalculator1.java:2: error: currentValue has private access in ICalculator
public int getCurrentValue() {return currentValue;}
^
ICalculator1.java:5: error: currentValue has private access in ICalculator
if(currentValue > -1) return 0;
^
ICalculator1.java:6: error: currentValue has private access in ICalculator
else if(currentValue < 0) return -1;
^
3 errors
Not sure what I'm doing wrong?