1. Analysis

  • Describe the problem including input and output
  • A stack is a good/bad choice as a data structure to use to match group symbols. Explain.

2. Design

  • Your UML design

A Java program contains various pairs of grouping symbols, such as:

  • Parentheses: ( and )
  • Curly braces: { and }
  • Brackets: [ and ]

Implement a program to check whether a Java source-code file has balanced parentheses, (); curly braces, {}; and square brackets, []. Use a stack to store the most recent unmatched left symbol. Any character that is not a parenthesis, curly brace, or square bracket should be ignored.

Note: Proper nesting is allowed. For example, {{(a(b)[]}} Grouping symbols cannot overlap. For example, (a{b)} is illegal.

Display the line number on which the error occurred.

Options

1. Create a program which runs from a command line and pass the Java file name as a command-line argument.

2. Create a program with a GUI which allows the user to select a Java file to open.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.