Question: In this assignment you are to start with the code base posted on the course s page on Canvas ( ListStack . java, ListNode.java, and
In this assignment you are to start with the code base posted on the courses page
on Canvas ListStackjava, ListNode.java, and StackDriver.java and modify the code
to implement additional functionality.
The only file you should be editing for this assignment is StackDriver.java which
already has certain functionality implemented in it such as evaluateExpr, and
isLegal. You must keep this functionality as is without editing.
Your program should implement the following functionality:
Implement a menudriven interface to be able to:
a Read an expression, check if its legal Use existing functionality
b Evaluate the inputted expression
i Only evaluate if the user inputted an expression, otherwise
indicate that no expression has been entered.
ii Once you evaluate this expression, its result should be printed
to the screen. Once evaluation is finished, the program must
require you to enter a new expression if this option is selected
again. But selecting this option should not prevent you from
performing part c with the same expression.
c Convert a fully parenthesized expression to postfix notation
i Only convert if the user inputted an expression, otherwise
indicate that no expression has been entered.
ii Once you convert the expression to postfix notation, you
should print the postfix notation to the screen. Once the
conversion is finished, the program must require you enter a
new expression if this option is selected again. But selecting
this option should not prevent you from performing part b
with the same expression.
d Evaluate a postfix notation expression
i In this option, your program should ask if the user would like
to enter a new postfix expression or use the postfix
expression that was converted in part c
ii If the user selects to use the postfix expression used in part c
then you need to verify that there is an expression to evaluate,
otherwise print an error message.
iii. If the user selects to enter a new postfix expression then make
sure that it is entered correctly, you have to do this manually,
no need to program the verification process.
e Quit
The menudriven interface should be an infinite loop that will only quit if the
user Quits the program, otherwise it should keep asking the user to select an
option. stack driver file import java.util.Scanner;
public class StackDriver
public static void mainString args
Scanner in new ScannerSystemin;
System.out.printEnter any parenthesized expression: ;String s innextLine;
ifisLegals
System.out.printlns is a legal parenthesization";
evaluateExprs;
else
System.out.printlns is a not legal parenthesization";
public static boolean isLegalString str
int i;
ListStack s new ListStack;
fori ; i strlength; i
ifstrcharAti
spush;
else ifstrcharAti
spop;
return sisEmpty;
public static void evaluateExprString str
int i;
ListStack s new ListStack;
ListStack s new ListStack;
fori ; i strlength; i
ifCharacterisDigitstrcharAti
spushintstrcharAti;
else ifstrcharAti strcharAti
strcharAti strcharAti
strcharAti
spushstrcharAti;
else ifstrcharAti
int opnd opnd;
char oper stopAndPop;
opnd stopAndPop;
opnd stopAndPop;
switchoper
case :
spushopnd opnd;
break;
case :
spushopnd opnd;
break;
case :
spushopnd opnd;
break;
case :
spushopnd opnd;
break;
case :
spushopnd opnd;
break; System.out.printlnThe result of the expression is: stopAndPop; liststack file public class ListStack
public ListStack
topOfStack null;
public boolean isEmpty
return topOfStack null;
public void makeEmpty
topOfStack null;
public void push AnyType x
topOfStack new ListNode x topOfStack ;public void pop
if isEmpty throw new UnderflowException "ListStack pop" ;
topOfStack topOfStack.next;
public AnyType top
if isEmptythrow new UnderflowException "ListStack top" ;return topOfStack.element;
public AnyType topAndPop
if isEmptythrow new UnderflowException "ListStack topAndPop" ;AnyType topItem topOfStack.element;
topOfStack topOfStack.next;returntopItem;privateListNodetopOfStack; listnode file class ListNode public ListNode AnyType theElement this theElement, null ; public ListNode AnyType theElement, ListNode n element theElement;next n; public AnyType element;public ListNodenext;
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
