Create a Java program to do the following using console input/output: a. Read in a string from the user b. Output "Valid" if the string contains a valid parenthesis pattern. c. Output "Invalid" if the string contains an invalid parenthesis pattern. A stack or queue is usually the easiest way to do this. In addition to user input, please hard-code the test cases into the main program so you don't have to input them manually each time. The program must still work on arbitrary input strings, not just the test cases. Examples: Test case input (We like ([your name here])) Life is easy Life is (fun) (We never) (forget) Call_Me() (1 (2 (3 (We all hate ([your least favorite band name here]) This is terrible. (((((())(0)0 )( Output Valid Valid Valid Valid Valid Invalid Invalid Invalid Invalid
Create a Java program to do the following using console input/output: a. Read in a string from the user b. Output "Valid" if the string contains a valid parenthesis pattern. c. Output "Invalid" if the string contains an invalid parenthesis pattern. A stack or queue is usually the easiest way to do this. In addition to user input, please hard-code the test cases into the main program so you don't have to input them manually each time. The program must still work on arbitrary input strings, not just the test cases. Examples: Test case input (We like ([your name here])) Life is easy Life is (fun) (We never) (forget) Call_Me() (1 (2 (3 (We all hate ([your least favorite band name here]) This is terrible. (((((())(0)0 )( Output Valid Valid Valid Valid Valid Invalid Invalid Invalid Invalid
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Include this code:
public static boolean isMatched(String expression) {
final String opening = "({["; // opening delimiters
final String closing = ")}]"; // respective closing delimiters
Stack<Character> buffer = new LinkedStack<>( ); // Using Textbook ADT, not Java library
for (char c : expression.toCharArray( )) {
if (opening.indexOf(c) != −1) // this is a left delimiter
buffer.push(c);
else if (closing.indexOf(c) != −1) { // this is a right delimiter
if (buffer.isEmpty( )) // nothing to match with
return false;
if (closing.indexOf(c) != opening.indexOf(buffer.pop( )))
return false; // mismatched delimiter
}
}
return buffer.isEmpty( );
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 2 images
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY