Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement the following method. You may use the IntStack class and the Stack ope

ID: 3645160 • Letter: I

Question

Implement the following method. You may use the IntStack class and the Stack operations of push, pop, peek, isEmpty, and size. The parameter, in, is an EasyReader and it is already attached to some kind of input. You may use the methods:

o in.isEOLN() -- returns true when the end of line is reached.
o in.peek() -- returns the next input character without actually reading it.
o in.ignore() -- reads and throws away the next input character.
o in.intInput() -- reads and returns an integer value from the EasyReader. This should be used only if you know that the next input characters form a valid integer value.
The method specification is:


public static int evaluatePostfix(EasyReader in)
// Precondition (Which is not checked): The next input line of in is a
// properly formed postfix expression consisting of integers,
// the binary operations + and -, and spaces.
// Postcondition: The method has read the next input line (including
// the newline) and returned the value of the postfix expression.

Explanation / Answer

import java.io.*; import java.util.*; public class StackImplement{ Stack stack; String str; int num, n; public static void main(String[] args){ StackImplement q = new StackImplement(); } public StackImplement(){ try{ stack = new Stack(); InputStreamReader ir = new InputStreamReader(System.in); BufferedReader bf = new BufferedReader(ir); System.out.print("Enter number of elements : "); str = bf.readLine(); num = Integer.parseInt(str); for(int i = 1; i