Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 Description Implement a class in Java named InfixToPostfixConverter containing the following meth ods. In an infix expression an operator is written in between the
1 Description Implement a class in Java named InfixToPostfixConverter containing the following meth ods. In an infix expression an operator is written in between the two operands. In contrast, in an postfix expression an operator is written aher the operands. Consider the following expression for explanation If the infix expression is 2 3 6 -1, then its pastfix version is 2 3 6 The program must not ask for any kind of input from the user. No file reading is required too. You must assume the following regarding the inpur infix expeessions: They will contain only integers as operands. The only operator they can contain are these four. /+. They will not contain any parenthesis or any kind of brace. A number and a operator are separat Example: 284433 49 9/ 67 and/have same priority +and-have same priority Priority of /is greater than that of+,- To reprent pv iority onr can aign integers to the openton Note that the methods are defined as public static. This means withoun creating an object, one should be able to use the methods. Just like the widely used Integer.parseInt(String s) method. In the following two methods, we need stacks for implementing the algorithm. You must define the stack class inside the InfixToPostfixConverter class 1 public static String infix2Postfix(String infixExpression); This method returns the posthx version of the infix expression passed to this method. But make sure that the operat and numbers are separated by a whisespace Algorithm. We use a Character stack in this algorithm. One by one, the items in the infixExpression is read, starting with the leftmost one. If the item is a number, append it to the return string followed by a whitespace. Otherwise, the item is an operator. Let us call it op. Now, as long as we see that the top operator in the stack has more or eqmal priority than op, keep on popping and appending to the retum string followed by whitespaces. Then push op into the stack I the infixExpression is read completely, pop every operator from the stack and uppend to the retum string followed by whitespaces 2. public static double postfixEvaluator(String postFixExpression); This method returns the value of the expression integers are separated by whitespaces. Make your method generalized such that it works even if two items are separated by more than one whitespace. You muust assume that the numbers and Algorithm. The following algorithm uses a Double stadk. Initially, the stack is empty. One by one, we read an item from the postFixExpression, start- ing with the leftmost one. When an item (operatoumber) is read from postFixExpression, we take one of the following two steps depending on the tem. If the item is a number, push it into the stack. Otherwise, the item must be an operator, call it op. In this case, we do the following . We pop a number from the stack and call it rightNumber Then we pop once more and call this number leftNunber . Next, we evaluate left Number op rightNumber and push the result to the stack At the end, the stack will contain the final value of the expression. Unles stateal,heprogams of thes corse you are not aload to use any exiting Java lwary and/For extemal packages for solving the proble. Yow shonld uvite everything from the scraich Yo leevezioprogram does mot compae or it is foured tevat yow huave copied cnde frows some esoitbout any nfve 2 Deliverable Upload the file InfixToPost fixConverter.java only You are not allowed to submit any other file. Your java code should be properly indented and nicely commented. Feel free so use additional helper methods, if required
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started