Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

image text in transcribed

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

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

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions