Assignment 04
You are given the main class RecursiveMethods.java which invokes methods that can be selected from a menu. Your task is to implement two of these methods.
-The first method isPal(s) determines whether a given string s is a palindrome. For example “12321” is a palindrome but “1231” is not. Currently the method isPal is a stub and you are expected to implement the method.
-The second method isSAE(s) determines whether the given string s is a strict arithmetic expression (see below). This method is fully implemented for you.
-The third method valueStrict(s) computes the value of the strict arithmetic expression s. Currently the method valueStrict is a stub and you are expected to implement the method using as a guide the implementation of isSAE(s).
The methods should be implemented using recursive methods, no points will be given for iterative solutions.
You should only need to work with the file RecursiveMethods.java but you will include your util1228 package for obvious reasons. Sample execution is shown below.
SUBMISSION NOTES
You will submit a single .jar file named A04.jar. Make sure that:
1) The jar file runs. In project properties under Run make sure the main class is set to a04.RecursiveMethods
2) The jar file includes all your source code. In project properties under packaging make sure .java files are not excluded. (see our Brightspace site for details about making JAR files)
IMPORTANT NOTES
A strict arithmetic expression (SAE) is one of the following:
1. Any nonnegative integer is a SAE (that is a nonempty string made of digits)
2. (x+y), (x*y), (-x), (+x), if x,y are SAEs
Strict arithmetic expressions do not allow spaces and do not allow omitting parentheses. The following are valid SAEs:
12, (-12), (3*5), ((3*5)+10), ((-3)*((-5)+10))
The following are NOT valid SAEs:
-12, 3*5, (-3)*5, (3), (5+4, (3 + 5)
SAMPLE EXECUTION
Menu
1. Test whether a given string is a palindrome
2. Test whether a given string is a strict arithmetic expression 3. Evaluate a strict arithmetic expression
4. Quit
Enter your choice here: 1 Enter a string: 1234321 “1234321” is a palindrome Press enter to continue…
Menu
1. Test whether a given string is a palindrome
2. Test whether a given string is a strict arithmetic expression 3. Evaluate a strict arithmetic expression
4. Quit
Enter your choice here: 3
Enter a strict arithmetic expression: ((3*5)+10) The value is 25
Press enter to continue…
Menu
1. Test whether a given string is a palindrome
2. Test whether a given string is a strict arithmetic expression 3. Evaluate a strict arithmetic expression
4. Quit
Enter your choice here: 3
Enter a strict arithmetic expression: (-3)*5 ERROR: invalid arithmetic expression Press enter to continue…
Menu
1. Test whether a given string is a palindrome
2. Test whether a given string is a strict arithmetic expression 3. Evaluate a strict arithmetic expression
4. Quit
Enter your choice here: 4 Buy!