Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please use Java while writing the pseudocode and apply the given instance. thank you! seems pretty clear. thank you. Question 2: (50 pts) Assume that

please use Java while writing the pseudocode and apply the given instance. thank you! image text in transcribed
image text in transcribed
image text in transcribed
seems pretty clear. thank you.
Question 2: (50 pts) Assume that we are given a number and we carry out a sequence of mathematical operations (multiplication, division, subtraction, summation on the number. Consider the stack data structure in Java to store the history of the mathematical operations. Then, use 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} 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 Undo() returns 10, and the current value of number is 10. stack = 0 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 Operation, 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

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

Recommended Textbook for

Intelligent Information And Database Systems Third International Conference Achids 2011 Daegu Korea April 2011 Proceedings Part 2 Lnai 6592

Authors: Ngoc Thanh Nguyen ,Chong-Gun Kim ,Adam Janiak

2011th Edition

3642200419, 978-3642200410

More Books

Students also viewed these Databases questions

Question

Differentiate 3sin(9x+2x)

Answered: 1 week ago

Question

Compute the derivative f(x)=(x-a)(x-b)

Answered: 1 week ago