Question: For this program, you are to write a brackets method called, check(). This method will be contained in the class called BracketChecker. This method will

For this program, you are to write a brackets method called, check(). This method will be contained in the class called BracketChecker. This method will check that for each left delimiter, {, [, (, a right delimiter exists, ), ], }, and in the correct order.

For example, if { [ ( ( ) ) ] } is passed to the BracketChecker class, the check() method would return true since for every left delimiter there is a corresponding right delimiter and in the proper order. However, if { [ ( ( ) ] } is passed, an error should be flagged at index 5. A second ) was expected and instead a ] was encountered. the method also would return false, since an error occurred.

Because the delimiters are last-in-first-out, (LIFO) you are to use a stack to insure that these delimiters are paired correctly. The user will enter the delimiters within the main() method and these delimiters will be passed to the BracketChecker class throught the constructor. The main() method that you are to use is given above. Again, do not make any modifications to the main() method. Use it as given.

For this program, you are to write a brackets method called, check().

This method will be contained in the class called BracketChecker. This method

public static void main(String[] args) \{ boolean flag = true; String input; Scanner keyboard = new Scanner(System.in); while(flag) \{ System.out.print("Enter string containing delimiters: "); input = keyboard .nextLine(); // read a string from kbd if( input.equals("') ) // quit if [Enter] flag = false; else \{ BracketChecker theChecker = new BracketChecker(input); // make a BracketChecker if (!theChecker.check()) System.out.printIn(" The delimiters are all correct. InThere were no errors ");// check brackets \} \}// end while \} run: Enter string containing delimiters: {()[()]} The delimiters are all correct. There were no errors Enter string containing delimiters: {()[(]} Brror: ] at 5 instead of Error: } at 6 instead of [ Brror: missing right delimiter to match left delimiter Enter string containing delimiters: [ Error: missing right delimiter to match left delimiter Enter string containing delimiters

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!