Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. Since the Java Collections classes always store objects, not primitives, you could process either a stack of Strings or of Characters. The shell below uses Strings.

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"); ArrayList parenExp = 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

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

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

LO2 Distinguish among three types of performance information.

Answered: 1 week ago