Question: can you solve it quickly please Question 2: (50 pts) Assume that we are given a number and we carry out a sequence of mathematical

can you solve it quickly please Question 2: (50 pts) Assume thatwe are given a number and we carry out a sequence ofcan you solve it quickly please

Question 2: (50 pts) Assume that we are given a number and we carry out a sequence of mathematical operations (multiplication, division, subtraction, sunmation) on the number. Consider the stack data structure in Java to store the history of the mathematical operations. Then, tise the same stack to revert the mathematical operations on a given number. Ex: number = 10 Storing history Operation 1: (first operand, type, second operand) = (number, 3) Do() returns 10 * 3 = 30, and the current value of number is 30. stack = {Operation 1) IE 211 Fall 2020 Homework #4 2/2 Operation 2: (first operand, type, second operand) = (number, +. 8) Do() returns 30 + 8 = 38, and the current value of number is 38. stack = {Operation 1. Operation 2} - Backtracking Last operation in the stack is Operation 2: (30. +. 8). Undo() returns 30, and the current value of number is 30. stack = {Operation 1) Last operation in the stack is Operation 1: (10.*.3). Undo() returns 10, and the current value of number is 10. stack = Define a class Operation which has fields for the first operand, operation type (*./.- +) and second operand. This class should also implement a method Do(), which returns the result of the operation, and a method Undo(), which returns the first operand's value. Let us given number = 10 initially and assume this value as the first operand. Randomly generate a operation type from (*./.-- +), and a value for the second operand in the range (1,20). Store this operation in a Stack, and implement Do() method to find the result. . Continue with the random operations on the current result (stored in number) for 5 times. Then, utilize stack methods to backtrack the operations and revert the operations via Undo() method. 1. (30 pts) With the guidance of the above steps write a Java code that implements the mathematical operations via stack. 2. (10 pts) Print the current value of the number to the console after each operation and reversion. 3. (10 pts) Report the console outputs and your Java code scripts

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!