2.) Postfix to infix translator (NOTE: This is NOT the evaluatoryou have already coded!) • Create a java class calledPostfixToInfixTranslator that includes a main method. • The codeyou write should prompt the user for an expression in postfixnotation and use ArrayStack to output the equivalent expression ininfix. • See the following session: Enter a postfix expression: 3 4+ 2 * In infix notation that is: ((3+4)*2) Translate anotherexpression [y/n]? y Enter a postfix expression: 4 2 + 3 5 1 - * +In infix notation that is: ((4+2)+(3*(5-1))) Translate anotherexpression [y/n]? n • NOTE: The postfix expression has to acceptspaces, double digit numbers, and negative numbers. So .charAt() isnot a good approach. Maybe a scanner on a string?
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
StackADT, EmptyCollectionException, and ArrayStack code alreadybelow, please use these.
public interface StackADT //Provide layout of what we wantsomething to do w/o supplying the way it gets done =interface
{
  public void push( T element) ;
 Â
  public T pop () throws EmptyCollectionException;
 Â
  public T peek() throws EmptyCollectionException;
 Â
  public boolean isEmpty();
 Â
  public int size();
}
public class EmptyCollectionException extends Exception
{
 Â
  private static final long serialVersionUID =358083002087971606L;
  public EmptyCollectionException()
  {
     super();
  }
 Â
  public EmptyCollectionException(String msg)
  {
     super(msg);
  }
}
import java.util.Arrays;
public class ArrayStack implements StackADT//We agree to supply all functions that we say exist StackADTFunctions correlate to ArrayStack
{
  private final static int DEFAULT_CAPACITY = 100;
  private int top;
  private T[] stack;
 Â
  public ArrayStack()
  {
     this(DEFAULT_CAPACITY);
  }
 Â
  @SuppressWarnings(\"unchecked\")
  public ArrayStack(int initialCapacity)
  {
     top = 0;
     stack = (T[]) new Object[initialCapacity]; //Have to cast Object Array to T array in orderfor placeholder to work. Java just works like that.
  }
 Â
  public void push( T element)
  {
     if(size() == stack.length)
        expandCapacity();
     stack [top] = element;
     ++top;
  }
 Â
  public T pop() throws EmptyCollectionException
  {
     if(isEmpty())
        throw newEmptyCollectionException();
     --top;
     T result = stack[top];
     stack [top] = null; // Top beforethat ends up being empty; Makes it clean
     return result;
  }
 Â
  public T peek() throws EmptyCollectionException
  {
     if(isEmpty())
        throw newEmptyCollectionException();
     return stack[top -1];
  }
 Â
  public int size()
  {
     return top;
  }
 Â
  public boolean isEmpty()
  {
     // Even shorter
     return top ==0;
     // Short
//Â Â Â Â Â boolean a = top == 0;
//Â Â Â Â Â return a;
     // long way
//Â Â Â Â Â if(top==0)
//Â Â Â Â Â Â Â Â returntrue;
//Â Â Â Â Â else
//Â Â Â Â Â Â Â Â returnfalse;
  }
 Â
  public void expandCapacity()
  {
     stack = Arrays.copyOf(stack,stack.length * 2); //Would values stay the same but only place inmemory changes? Hexa decimal #'s?
  }
 Â
  public String toString()
  {
     String output = \"ArrayStack-> [\";
     for(int i =top-1; i >=0 ;i--)
     {
        output+=stack[i].toString() + \" \";
     }
    Â
     output+= \"]\";
     return output;
  }
}
WHAT I ALREADY HAVE CODED IN TRANSLATOR, PLEASE HELP. I don'tknow how to allow spaces, double digits, and negative numbers, andalso how to loop the scanner input.
import java.util.Scanner;
import java.util.Stack;
public class PostfixToInfixTranslator
{
  public static void main(String[] args) throwsEmptyCollectionException
  {
     PostfixToInfixTranslator obj = newPostfixToInfixTranslator();
     Scanner sc = newScanner(System.in);
     System.out.print(\"Postfix :\");
     String postfix = sc.next();
     System.out.println(\"Infix : \"+obj.convert(postfix));
    Â
  }
  private boolean isOperator(char c)
  {
     if(c == '+' || c== '-' || c== '*'|| c=='/' || c=='^')
        returntrue;
     return false;
  }
 Â
  public String convert(String postfix) throwsEmptyCollectionException
  {
     ArrayStack s = newArrayStack<>();
    Â
     for(int i =0; i      {
        char c =postfix.charAt(i);
        if(isOperator(c))
        {
           String b = s.pop();
           String a = s.pop();
           s.push(\"(\"+a+c+b+\")\");
        }
        else
           s.push(\"\"+c);
     }
     return s.pop();
  }
}