Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Convert 7052 to Binary and then Hex.

Answered: 1 week ago

Question

5. How would you describe your typical day at work?

Answered: 1 week ago

Question

7. What qualities do you see as necessary for your line of work?

Answered: 1 week ago