Question: The goal for this assignment is to implement Stack ADT using arraylist or linkedlist implementation. develop program (another Class) to use MyStack class to solve

The goal for this assignment is to implement Stack ADT using arraylist or linkedlist implementation. develop program (another Class) to use MyStack class to solve practical problem. Part 1: (10 points) Develop a new class, called MyStackYourname, to implement, among others, key stack operations [push(e), pop(), peek(), size(), isEmpty(), toString()]. Again, class Stack needs to be defined as generic stack with type so that we can create stack objects that can hold data of different types, such as integer stack, string stack, char stack, double stack, etc. MyStackYourname Class must have these methods methodname(argument): returnType isEmpty(): boolean Returns true if this stack is empty size(): int Returns the number of elements in this stack peek(): E Returns the top element in this stack pop(): E Returns and removes the top element in this stack push(E element): E Adds a new element to the top of this stack toString(): String Returns the String with all elements in current stack // based on your choice, toString will return the String with all elements in order [top to bottom] or [bottom to top] You cannot change method names, return type and parameter types. To evaluate your Class's methods, the instructor will use another Test Program and will invoke your methods based on the class definition above. Next, develop a simple test program in a new class called TestStackYourname to test all stack methods(operation) listed above and defined in your class MyStackYourname. [Part 2&3&4 must be implemented as ONE Class] Implement a class, call it ExprYourname, which will be used for transform the expressions(infix to postfix) and evaluate postfix. Part 2: (10 points) code a method public static String infixToPostfix(String infix){ // Write appropriate codes here to transform infix to postfix // Return postfix as a String } Input is a String in infix, and the output must be corresponding postfix expression of the input. Use your MyStackYourname to code a method for infix to postfix transformation. Use the algorithm of infix to postfix translation which is introduced in the lecture. Assumptions: All input number is one-digit number. (a positive digit 0 to 9) Input infix can include parenthesis ( ) Only five types of operators + - * / ^ can be used. The output postfix string doesn't have whitespaces. Part 3: (10 points) In ExprYourname above, implement another method, call it postfixEval, which prompts the user to enter a string value of postfix expression. Using class StackYourname, the program should evaluate the postfix expression and return the correct calculated result. code a method public static double postfixEval(String postfix){ // Write appropriate codes here // Return calculated result } Assumption: Input postfix string doesn't have whitespaces. All input number is one-digit number. (positive digit 0 to 9) Operator + - * / ^ can be used If postfix input is not calculatable, show the message (to say it's an invalid postfix) Part 4: (10 points) develop a main method which tests above two methods (Part 2 and Part 3) develop a method public static void main(String[] args){ // What is the process of main method. // - User will insert infix // - Invoke infixToPostfix to transform it to postfix expression // - Invoke postfixEval to evaluate postfix expression // - Show the calculated result // Write appropriate codes here } // Two examples Enter an infix: (7+3)*(3-1)/2 //user input infix Postfix Evaluation: 73+31-*2/ Result value: 10 Enter an infix: (5-6)/4*2-(5+2) //user input infix Postfix Evaluation: 56-4/2*52+- Result value: -7.5 //you can ignore how many numbers of digits after decimal point

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!