Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Finish the java calculator class below. a. Make the following changes to the Calculator class. i. ii. iii. The add method should add the parameter

Finish the java calculator class below.

image text in transcribedimage text in transcribed

image text in transcribed

a. Make the following changes to the Calculator class. i. ii. iii. The add method should add the parameter to the total variable The subtract method should subtract the parameter from the total variable The getTotal method should return the current total The multiply method should multiply the total by the parameter The divide method should divide the total by the parameter. Use integer division. If the parameter is zero, set the total to zero. Do not print an error message or rasise an exception.. The getHistory method should NOT be changed at this time and should continue to return an empty String iv. iV. v. vi. Make the changes to the Calculator class as needed so that the getHistory method will return a history of all actions as a String. a. i. ii. iii. The history should start from the initial 0 value to the last input. Use the normal operators for the operations (+, -, *, /) There is no limit on the size of the String returned. The return String should separate all operations and values with a space For example iv. 1V myCalculator.add (4); myCalculator.subtract (2); myCalculator.multiply (2); myCalculator.add(5); then the history method should return 0+4-2 2 +5 Add other variables if needed to the class. Any additional variables must be private. Make changes to the other methods if needed v. package cse360assign3; public class Calculator private int total; public Calculator ) ( total-0 / not needed - included for clarity public int getTotal return 0; public void add (int value)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions