Question: It's a java code and should be like the example below, you have to use stack tho Your task is to use a stack to

It's a java code and should be like the example below, you have to use stack tho

It's a java code and should be like the example below, youhave to use stack tho Your task is to use a stack

Your task is to use a stack to implement a calculator with undo functionality. Your calculator should support addition, subtraction, multiplication and division. In addition, typing 'u' should undo the most recent operation and typing 'q' should quit the program. Your program should begin by creating a stack of Doubles and pushing the starting value 0.0 onto the stack. Following this, it should enter a loop in which it displays the current total (i.e. the number on the top of the stack) and then reads in a command and executes the appropriate action. Commands can be of two forms: an arithmetic operator +-or /) followed by a decimal number or a character command (u or q). If the command is of the first type, execute the appropriate operation and push the new value onto the stack. If the command is u, manipulate the stack to undo the most recent arithmetic operation. If you are already back at the first operation, then display the message "Nothing to undo." If the command is q, the program should exit. An example execution is shown below. Note that you should warn the user if their input is not a valid command

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!