Question
Make an ArrayList of expressions with grouping symbols and output whether the grouping symbols match. Test for ( ), [ ], { }, and <
Make an ArrayList of expressions with grouping symbols and output whether the grouping symbols match. Test for ( ), [ ], { }, and < >. Type in the test data as shown in the sample run below. Use only the stack methods in java.util.Stack
That is the assingment
import java.util.*; public class ParenMatch { public static final String LEFT = "([{<"; public static final String RIGHT = ")]}>"; public static void main(String[] args) { System.out.println("Parentheses Match"); ArrayListparenExp = new ArrayList (); /* enter test cases here */ for( String s : parenExp ) { boolean good = checkParen(s); if(good) System.out.println(s + "\t good!"); else System.out.println(s + "\t BAD"); } } //returns the index of the left parentheses or -1 if is not public static int isLeftParen(String p) { return LEFT.indexOf(p); } //returns the index of the right parentheses or -1 if is not public static int isRightParen(String p) { return RIGHT.indexOf(p); } public static boolean checkParen(String exp) { } } /***************************************** Parentheses Match 5 + 7 good! ( 15 + -7 ) good! ) 5 + 7 ( BAD ( ( 5.0 - 7.3 ) * 3.5 ) good! < { 5 + 7 } * 3 > good! [ ( 5 + 7 ) * ] 3 good! ( 5 + 7 ) * 3 good! 5 + ( 7 * 3 ) good! ( ( 5 + 7 ) * 3 BAD [ ( 5 + 7 ] * 3 ) BAD [ ( 5 + 7 ) * 3 ] ) BAD ( [ ( 5 + 7 ) * 3 ] BAD ( ( ( ) $ ) ) good! ( ) [ ] good! *******************************************/
That is the shell code we were given. I am posting this again because last time I think my directions were not as clear and some of the test cases failed. I need to meet all of them and use leftParen and Rightparen but I can't figure out how to do so.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started