Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java memory calculator: Hi, I need help with this project. Here are the instructions: For this assignment we're going to make another calculator. This one

Java memory calculator:

Hi, I need help with this project. Here are the instructions:

For this assignment we're going to make another calculator. This one will be a simple four function (add, subtract, multiply, and divide) calculator, but it will have state. Specifically, the calculator will keep track of the result of the most recent operation and use that value as the first operand for the next operation. Take a look at the sample output below if this doesn't quite make sense. Your new calculator class should have the following fields and methods: fields: private double currentValue methods:

public static int displayMenu()

public static double getOperand(String prompt)

public double getCurrentValue()

public void add(double operand2)

public void subtract(double operand2)

public void multiply(double operand2)

public void divide(double operand2)

public void clear() The displayMenu option should allow the user to pick from these options: add, subtract, multiply, divide, clear, and quit. If the user has entered an invalid option, it should reprompt them. Once a valid option has been entered, the method should return it.

The getOperand method displays the prompt to the user, reads in a double value, and returns it.

The getCurrentValue method just returns the number stored in the currentValue field. The add, subtract, multiply, and divide methods now only need to take one parameter because the first operand will be the currentValue field.

Also, these methods do not need to return the result. Instead, they should store it in the currentValue field. The clear method should reset the currentValue to zero. DO NOT make the currentValue field static.

With currentValue as an instance field, we can eventually write a program that allows users to have multiple calculators running, each computing different things. Note that because currentValue is an instance field, the methods that change it, such as add, subtract, multiply, and divide, must be instance methods.

Methods such as displayMenu and getOperand can remain static because they do not need to access the state of the calculator.

Once you have all of the methods written, write a main method that creates an instance of your calculator class.

Write a loop that displays the current value (initially it will be zero), asks the user what operation they want to perform, computes the result, and repeats until the user chooses to quit.

Here is the grading rubric:

You will be graded according to the following rubric (each item is worth one point): The Calculator class has the fields and methods specified, with the correct data types, access modifiers, and signatures

The getMenuOption method displays the given choices, validates the input, and returns it

The add, subtract, multiply and divide methods update the currentValue field

The clear method resets the currentValue field to zero

The main method declares an initializes a Calculator object

The instance methods (add, subtract, multiply, divide, and clear) are correctly called from main through the Calculator object

The static methods (displayMenu and getOperand) are correctly called from main

The program compiles

The program runs

You follow standard coding conventions (e.g. variable names, indentation, comments, etc.)

Note: If your program does not compile, you will receive a score of 0 on the entire assignment

Note: If you program compiles but does not run, you will receive a score of 0 on the entire assignment

Note: If your Eclipse project is not exported and uploaded to the eLearn drop box correctly, you will receive a score of 0 on the entire assignment

Note: If you do not submit code that solves the problem for this particular assignment, you will not receive any points for the programs compiling, the programs running, or following standard coding conventions.

Also, I have an older version of the calculator with a working menu and other functions that might help here is the code for that :

https://paste.ofcode.org/tyzD3vZQCtLMczbFyERUZP

Thank you so much!!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Question

What is the preferred personality?

Answered: 1 week ago