$20
Objective:
The objective of this lab is to get you some experience in testing, debugging and exception handling.
The lab assignment:
Test your infix evaluator program with the following test cases.
12 + (34 – 56) * 78 )
12 + (( 34-56) * 78
12 + 34 56
12 + * 34
Obviously, you will either get an exception or wrong output for each of the test cases.
If the test case produces an exception, you can locate the error from the call stack trace generated by the JVM. Example,
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1 at StackQueue.Stack.pop(Stack.java:10) at infix.evaluePostfix(infix.java:59) at infix.main(infix.java:83)
Insert code into your program to catch the exception and, throw, catch, and print your own exceptions.
If the test case doesn’t produce any exception, use jdb to step through you program in order to locate the error.
Insert some error checking code to throw, catch, and print your own exceptions
Your new program should produce outputs similar to the following.
D:\lab05\>java infix2
Enter infix: 12 + (34 - 56) * 78 )
***** Too many ) *****
Enter infix: 12 + (( 34-56) * 78
***** Too many ( *****
Enter infix: 12 + 34 56
Postfix is 12 34 56 +
***** Too many operands *****
Enter infix: 12 + * 34
Postfix is 12 34 * +
***** Too many operators ****
Notes:
You must use jdb for at least one test case.
Open two athena windows.
In one window, do java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=20000 infix
In the other window, do jdb -attach 20000
Use command script to record a jdb session.
To get whole credit for this lab:
Demo with the four test cases and “12+34*(56-7)-18/9”.
Turn in a hardcopy of infix.java.
Email a softcopy of java and the file typescript.