600.108 Intro Programming Lab Week 11 PROBLEM STATEMENT: Write a program which will randomly generate five balanced, properly formed series of parentheses (), braces {}, brackets [] and angles <>. A series is properly formed if each left symbol has a matching right symbol, and all subseries are sequentially placed next to other subseries or fully nested within a pair of matched symbols. Examples of proper combinations are: ({}<>) or [{<>}(({[]})<>)]. Examples of improper combinations are: ({}] (mismatch) or ({}[)] (bad nesting). You MUST USE A RECURSIVE METHOD to create each series. The only user input should be the length of each series (must be an even number). If you are confused by this definition, check out the method in the recursion sample program from lectures that has a method to determine if a string is a properly balanced expression: www.cs.jhu.edu/~joanne/cs107/code/recursion.java ------------------ RULES for your solution -------------------------- 1) The only global variables allowed are a Random object, a keyboard object for input, and a constant String or array to hold the set of valid symbol characters. That's it! 2) Your recursive methods may not print anything. You can only print from main. ---------------------------------------------------------------------- Phase I: Write a recursive method that creates a nested set of parentheses. It must take a parameter for the number of nested pairs; e.g., 5 produces ((((())))). Write a main method demonstrating this functionality. Phase II: Change your recursive method to randomly choose any combination of these four symbol pairs: {}, [], (), or <>. They must match correctly with their other half in the nesting, such as (([<{}>])). Phase III: Change your main method so that it will generate 5 different sets of symbols, getting user input for the total length of each set. Do error checking to make sure that each input is an even number. Phase IV: Write a second recursive method that creates a sequence of matched symbols, chosen from the same four in Phase II. It must have a parameter specifying the number of pairs in the sequence. For example, 5 may produce (){}[][]<>. Call this method from main so that for each user input, two things are printed: a nested series and a sequenced series. (over) Phase V: Now create a third recursive method that creates a series of matched symbols that is any combination of nested or sequenced. Make sure that all valid combinations are equally likely. This method should also have a parameter indicating the size of the series. Call this method on all the input values (in addition to the first two method calls) and print the result. Don't try to call the nested or sequenced methods from the previous phases in this method. They were just warm-ups. Make this method recurse on itself instead, adapting code from the other two. ************************************************** MAKE SURE YOU DELETE YOUR FILES OFF THE LAB COMPUTER WHEN DONE!!! FAILURE TO DO SO IS AN ETHICS VIOLATION! **************************************************