Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume the availability of an existing class, ICalculator, that models an intege

ID: 3652343 • Letter: A

Question

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
methods 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.

Explanation / Answer

public class ICalculator1 extends ICalculator { public int sign() {return Integer.signum(getCurrentValue());}}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote