Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Implement your own ADT-list-based stack class named stackListBased. Use the ADT LinkedList of the Java Collections Framework. Your Stack implementation should be capable of

image text in transcribed

image text in transcribed

2. Implement your own ADT-list-based stack class named stackListBased. Use the ADT LinkedList of the Java Collections Framework. Your Stack implementation should be capable of performing the operations shown in the following UML diagram. Stack top items createStack () PoPAZ1 ( isEmpty push () Pop peek () Design another class named InfixCalculator to implement an infix calculator using your previously implemented class StackListBased. The InfixCalculator class must accept infix expressions from the user and evaluate them with method evaluateInfix. This method will first convert the infix expression to postfix expression (method convertPostfix), and then evaluate the resulting postfix expression (method getPostfix). Use only the operators +, -, *, and /. You can assume that the infix expression is syntactically correct and that the unary operators are illegal. However, the infix expression should a. allow for any type of spacing between operands, operators, and parentheses b. allow for multi-digit integer operands The client program (exterior to your class) will read the infix expression to evaluate from the keyboard as follows: Enter the infix expression to evaluate: Suppose that the user enters the expression: (10 3* 4/ 6) The client program will then proceed to create an object of your class with the user- entered expression and evaluate it the method evaluateInfix() The output for some example infix operations should appear as follows infix: (103 * 4/ 6) postfix: 10 3 4 *6/+ result: 12 infix: 12*3 4 (18 / 6) postfix: 12 3 *4 18 6 /+ result: 35 infix: 35 42* 17 /2 + 10 postfix: 35 42 17 * 2 / - 10 -+ result: -312 infix: 3 * (4 +5) postfix: 3 45+ * result: 27 infix: 3 * (17 - (5+2))/(2+3) postfix: 3 17 5 2+*2 3/ result: 6 2. Implement your own ADT-list-based stack class named stackListBased. Use the ADT LinkedList of the Java Collections Framework. Your Stack implementation should be capable of performing the operations shown in the following UML diagram. Stack top items createStack () PoPAZ1 ( isEmpty push () Pop peek () Design another class named InfixCalculator to implement an infix calculator using your previously implemented class StackListBased. The InfixCalculator class must accept infix expressions from the user and evaluate them with method evaluateInfix. This method will first convert the infix expression to postfix expression (method convertPostfix), and then evaluate the resulting postfix expression (method getPostfix). Use only the operators +, -, *, and /. You can assume that the infix expression is syntactically correct and that the unary operators are illegal. However, the infix expression should a. allow for any type of spacing between operands, operators, and parentheses b. allow for multi-digit integer operands The client program (exterior to your class) will read the infix expression to evaluate from the keyboard as follows: Enter the infix expression to evaluate: Suppose that the user enters the expression: (10 3* 4/ 6) The client program will then proceed to create an object of your class with the user- entered expression and evaluate it the method evaluateInfix() The output for some example infix operations should appear as follows infix: (103 * 4/ 6) postfix: 10 3 4 *6/+ result: 12 infix: 12*3 4 (18 / 6) postfix: 12 3 *4 18 6 /+ result: 35 infix: 35 42* 17 /2 + 10 postfix: 35 42 17 * 2 / - 10 -+ result: -312 infix: 3 * (4 +5) postfix: 3 45+ * result: 27 infix: 3 * (17 - (5+2))/(2+3) postfix: 3 17 5 2+*2 3/ result: 6

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_2

Step: 3

blur-text-image_3

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

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions

Question

Distinguish between poor and good positive and neutral messages.

Answered: 1 week ago

Question

Describe the four specific guidelines for using the direct plan.

Answered: 1 week ago