Question: Assignment11.java import java.io.*; public class Assignment11 { public static void main (String[] args)throws IOException { char input1; String inputInfo; String line = new String(); printMenu();

Assignment11.java
import java.io.*; public class Assignment11 { public static void main (String[] args)throws IOException { char input1; String inputInfo; String line = new String(); printMenu(); InputStreamReader isr = new InputStreamReader(System.in); BufferedReader stdin = new BufferedReader(isr); do // will ask for user input { System.out.print("What action would you like to perform? "); line = stdin.readLine(); input1 = line.charAt(0); input1 = Character.toUpperCase(input1); if (line.length() == 1) { // matches one of the case statements switch (input1) { case 'E': //Enter String System.out.print("Please enter a string. "); inputInfo = stdin.readLine().trim(); System.out.print(InfixToPostfixConverter.convertToPostfix(inputInfo)+" "); break; case 'Q': //Quit break; case '?': //Display Menu printMenu(); break; default: System.out.print("Unknown action "); break; } } else { System.out.print("Unknown action "); } } while (input1 != 'Q' || line.length() != 1); } /** The method printMenu displays the menu to a user**/ public static void printMenu() { System.out.print("Choice\t\tAction " + "------\t\t------ " + "E\t\tEnter String " + "Q\t\tQuit " + "?\t\tDisplay Help "); } }InfixToPostfixConverter.java (To be completed by you)
import java.util.Stack; public class InfixToPostfixConverter { //********************************************************************** //The precedence method determines the precedence between two operators. //If the first operator is of higher or equal precedence than the second //operator, it returns true, otherwise it returns false. //*********************************************************************** public static boolean precedence(char first, char second) { } //************************************************************************* //The static convertToPostfix method will convert the infixString //into the corresponding postfix string. Check the algorithm on //assignment #11's description page. Mark each case clearly inside the code //************************************************************************* public static String convertToPostfix(String infixString) { //initialize the resulting postfix string String postfixString = ""; //initialize the stack Stack stack1 = new Stack(); //Obtain the character at index i in the string for (int i=0; i Program Description In this assignment, you're required to write a program to convert an infix notation to its corresponding postfix notiation by using the Stack data structure. In arithmatics, the infix notation is like (A+B)*C, where the operators,+ and *, are written between the operand, A, B and C. The corresponding postfix notation is AB+C*, where the operators follow the operands. Postfix notation has the advantage that.: . It does not require parentheses The operators appear in the order required for computation Below please find the algorithm that converts an infix notation to a postfix notation . Initialise an empty stack. 2. Scan the Infix string from left to right, one charater at a time, depends on which character you have, there are several cases here Case A: If the scannned character is an operand, add it to the Postfix string Case B: If the scanned character is a left parenthesis, just push it on top of the stack . Case C: If the scanned character is an operator and the stack is empty, push the character on top of the stack . Case D: If the scanned character is an operator and the stack is not empty, compare the precedence of the character with the element on top of the stack (topStack). If topStack has higher precedence over the scanned character, Pop the stack and append it to Postfux string, else push the scanned character on top of the stack. Repeat this step as long as stack is not empty and topStack has precedence over the character. Case E: If the scanned character is a right parenthesis and the stack is not empty, pop everything out from the stack and append them one by one to Postfix string until we encounter the first left parenthesis on stack, then stop. (Note: the first encountered left parenthesis on stack will be pop out and discarded). If there's no left parenthesis to match the right parenthesis, return a "No matching open parenthesis error as output. 3. Repeat above steps until all the characters in infix notation are scanned. 4. Case F: After all characters in infix notation are scanned, we then check the contents of the stack. If topStack is a left parenthesis, return a "No matching close parenthesis error" string as output and stop. If the stack is not empty and topStack is not a left parenthesis, we pop it out and append it to the Postfix string. Repeat this step as long as stack is not empty. In other words, we have to add any characters other than the left parenthesis that the stack may have to the Postfix string. 5. Return the Postfix string. Program Description In this assignment, you're required to write a program to convert an infix notation to its corresponding postfix notiation by using the Stack data structure. In arithmatics, the infix notation is like (A+B)*C, where the operators,+ and *, are written between the operand, A, B and C. The corresponding postfix notation is AB+C*, where the operators follow the operands. Postfix notation has the advantage that.: . It does not require parentheses The operators appear in the order required for computation Below please find the algorithm that converts an infix notation to a postfix notation . Initialise an empty stack. 2. Scan the Infix string from left to right, one charater at a time, depends on which character you have, there are several cases here Case A: If the scannned character is an operand, add it to the Postfix string Case B: If the scanned character is a left parenthesis, just push it on top of the stack . Case C: If the scanned character is an operator and the stack is empty, push the character on top of the stack . Case D: If the scanned character is an operator and the stack is not empty, compare the precedence of the character with the element on top of the stack (topStack). If topStack has higher precedence over the scanned character, Pop the stack and append it to Postfux string, else push the scanned character on top of the stack. Repeat this step as long as stack is not empty and topStack has precedence over the character. Case E: If the scanned character is a right parenthesis and the stack is not empty, pop everything out from the stack and append them one by one to Postfix string until we encounter the first left parenthesis on stack, then stop. (Note: the first encountered left parenthesis on stack will be pop out and discarded). If there's no left parenthesis to match the right parenthesis, return a "No matching open parenthesis error as output. 3. Repeat above steps until all the characters in infix notation are scanned. 4. Case F: After all characters in infix notation are scanned, we then check the contents of the stack. If topStack is a left parenthesis, return a "No matching close parenthesis error" string as output and stop. If the stack is not empty and topStack is not a left parenthesis, we pop it out and append it to the Postfix string. Repeat this step as long as stack is not empty. In other words, we have to add any characters other than the left parenthesis that the stack may have to the Postfix string. 5. Return the Postfix string Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
