Question: JAVA -- Using the static method public static boolean containsMismatchedParentheses(List source){...}, implement a mismatched parentheses checker that highlights mismatched parentheses. This list of strings source

JAVA --

Using the static method public static boolean containsMismatchedParentheses(List source){...}, implement a mismatched parentheses checker that highlights mismatched parentheses. This list of strings source contains a String for each line of code in some source file. It returns true if the list of strings contains mismatched parentheses and false otherwise. You can use java.util.Stack.

If mismatched parentheses are discovered while processing the lines of the file, an error message should be printed to standard out stating one of the following:

System.out.printf(Error. Closing } encountered. %s popped off the stack. , stack.pop())

System.out.printf(Error. Closing ] encountered. %s popped off the stack. , stack.pop())

System.out.printf(Error. Closing ) encountered. %s popped off the stack. , stack.pop())

If the stack is not empty after processing every line, one or more opening parentheses were not closed in the file. This case should be handled as well. Print "stack not empty, not all parentheses closed."

if all parentheses are balanced, print "Parentheses are balanced."

Also, implement a main method that reads in a source file, adds each line to a list of strings, and runs containsMismatchedParenthese on the list (the main method must handle an IOException, you can use a Scanner wrapping a FileInputStream to read in the source to check, the path to the file to be checked must be read in from the args[0] element of the command line arguments array).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!