Using java language please and if you can explain each step would be amazing. Regarding the 2nd
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider the following method matchBrackets for brackets matching: public static boolean matchBrackets (String str) Arraystacks = new Arraystack (100) ; char ch; for (int i=0; i<str.length (); ++i) { ch=str.charAt (i); if (ch=='{' || ch==' (' l|ch=='[' ) { S.push (ch); } else if (ch=='}' || ch==')' ||ch==']' ) { if (s.isEmpty ()) return false; switch (S.pop ()) { case '{': if (ch!='}') return false; break; case '[': if(ch!=']') return false; if (ch!=')') break; break; case '(': }//End of switch return false; } // End of for loop if (s.isEmpty ()) return true; else return false; }//End of method matchBrackets 1. Rewrite the above method using recursion, keeping the same variables. You may add more arguments to matchBrackets. 2. Test the above recursive method in main() that reads several expressions from an input file "MatchExpression.txt"and writes the results in a output file "MatchResults.txt". Test your program using the following expressions stored in "MatchExpression.txt": () ()){([() 1) } ((() (()){([() 1)} ({[]}) {[]} () ) (()){([()) } Consider the following method matchBrackets for brackets matching: public static boolean matchBrackets (String str) Arraystacks = new Arraystack (100) ; char ch; for (int i=0; i<str.length (); ++i) { ch=str.charAt (i); if (ch=='{' || ch==' (' l|ch=='[' ) { S.push (ch); } else if (ch=='}' || ch==')' ||ch==']' ) { if (s.isEmpty ()) return false; switch (S.pop ()) { case '{': if (ch!='}') return false; break; case '[': if(ch!=']') return false; if (ch!=')') break; break; case '(': }//End of switch return false; } // End of for loop if (s.isEmpty ()) return true; else return false; }//End of method matchBrackets 1. Rewrite the above method using recursion, keeping the same variables. You may add more arguments to matchBrackets. 2. Test the above recursive method in main() that reads several expressions from an input file "MatchExpression.txt"and writes the results in a output file "MatchResults.txt". Test your program using the following expressions stored in "MatchExpression.txt": () ()){([() 1) } ((() (()){([() 1)} ({[]}) {[]} () ) (()){([()) }
Expert Answer:
Answer rating: 100% (QA)
PLEASE LIKE THE SOLUTION FEEL FREE TO DISCUSS IN COMMENT SECTION A java program to check balanced pa... View the full answer
Related Book For
Accounting Principles
ISBN: 978-1118342190
11th Edition
Authors: Jerry Weygandt, Paul Kimmel, Donald Kieso
Posted Date:
Students also viewed these programming questions
-
Your best friend from home writes you a letter about an investment opportunity that has come her way. A company is raising money by issuing shares and wants her to invest $ 20,000 (her recent...
-
This code must be in C++ In this assignment, you are to take in input from two files: one file containing a list of five first names and one file containing a list of five last names. Using this...
-
An investor may choose from several investment opportunities: the stocks of different companies; rental property or other real estate; or savings accounts, money market certificates, and similar...
-
Using mean-variance portfolio theory, prove that the efficient frontier becomes a straight line in the presence of a risk-free asset. [3] Consider two independent assets, Asset A and Asset B, with...
-
A firm produces cellular telephone service using equipment and labor. When it uses E machine-hours of equipment and hires L person-hours of labor, it can provide up to Q units of telephone service....
-
Love them or hate them Crocs are back, and they are undoubtedly here to stay! It has been a tough road for Crocs, which has been around for nearly 20 years. Crocs made its first appearance in...
-
Water is to be used to absorb acetone from a dilute mixture with air in a tower packed with 3.5-in. metal Pall rings. Average conditions in the tower are: \[\text { Temperature }=25^{\circ}...
-
Recording Bad Debt Expense Estimates and Write-Offs Using the Percentage of Credit Sales Method During 2011, Crandell Productions, Inc., recorded credit sales of $800,000. Based on prior experience,...
-
Explain Employee and labor/managers relation: Why is it important? Why is it challenging? What is important to a supervisor? What is important to an employee?
-
Cardinal Company is considering a five-year project that would require a $2,975,000 investment in equipment with a useful life of five years and no salvage value . The company's discount rate is 14%....
-
Tiger Company was established on January 1, 2018. Along with other assets, it immediately purchased land for $100,000, and a building $120,000. On January 1, 2021, Tiger transferred these assets,...
-
3. Suppose that (Xn)nzo is a Markov chain on a state space I = {1, 2, 3, 4, 5}, initial distribution A = = (1/3, 0, 0, 1/6, 1/2) and stochastic matrix [1/4 1/4 1/4 0 1/4] 0 0 5/6 0 1/6 P = 1/3 0 1/5...
-
5. If a spacecraft was approaching an object of large mass what would happen to the radio signals transmitted from the spacecraft as it gets closer to the mass?
-
A farmer named Ben attempts to remove an 80-kg rock from his field. He applies a force of 789 N for 10 seconds but could not move the rock. How much work has he done?
-
On December 16, 2016, the ACE Corporation purchases? $15,000 of equipment by issuing a 30-?day, 12% note payable.What is The total amount of interest due on the note?
-
A person pulls on the handle of a lawnmower with a force of 280 N. If the handle makes an angle of 40.0 degrees with the ground, calculate the coefficient of friction if the lawnmower weighs 350 N...
-
Accounting 1C Long Term Project- Master Budget You need to prepare a Master Budget for the The company has an exclusive right to sell PowerPulses and sales have been brisk. The Master Budget will be...
-
Use the following data to answer the next two (2) questions: Product 1 Product 2 Product 3 Direct Material Cost $25,000 $30,000 $35,000 Direct Labor Cost $30,000 $40,000 $50,000 Direct Labor Hours...
-
The partners in Crawford Company decide to liquidate the firm when the balance sheet shows the following. The partners share income and loss 5:3:2. During the process of liquidation, the following...
-
Which of the following accounts would not appear in the post-closing trial balance? Interest Payable; Equipment; Depreciation Expense; Jennifer Shaeffer, Drawing; Unearned Revenue; Accumulated...
-
Manufacturing cost data for Copa Company are presented below. Instructions Indicate the missing amount for each letter (a) through(i). Case A Case B Case C $68,400 $130,000 102,000 Direct terials...
-
Often a linearly sloped beach is not a good model. Waves coming from deep water up a gradually shelving beach are better approximated by assuming a parabolic shape like that shown in Figure P7.6...
-
In the design of a horn tweeter, which parameter is most critical in specifying where the cutoff frequency for the loudspeaker would lie? Why?
-
Is wavelike motion an example of conservative or diffusive motion?
Study smarter with the SolutionInn App