judiMc / oopExamples

repository to contain the solutions for the practice problems for the scioer e-text on oo programming in java.
GNU Affero General Public License v3.0
1 stars 0 forks source link

ooConcepts/calcWithClassMembers #6

Open judiMc opened 2 years ago

judiMc commented 2 years ago

This practice problem builds on the one presented as practice problem for Instance Variables. If you have not completed that activity, please do so. Add a constant to your calculator that represents the mathematical value of PI. Add two static methods to the Calculator, one that compares two doubles and returns the largest of the two numbers. The second static method should return the square of the parameter value(a double). Finally, add a class variable to your calculator that is a shared variable that allows calculators to share a value with other calculators. Call this class variable register. Write an instance method called addToRegister() that takes a double as a parameter and adds that value to the register and returns the new value. Write a second instance method that resets the register to zero. Test your revised calculator thoroughly in the Runner class. In particular make sure you experiment with using the register class variable to share data between instances of the Calculator.