Question: JAVA PROGRAMMING For this programming assignment, you will implement of a java program that generates a random string of a given length and finds different
JAVA PROGRAMMING
For this programming assignment, you will implement of a java program that generates a random string of a given length and finds different special patterns in the string using the concept of Exception Handling in Java. Flow of the Program Input from System.in At the beginning, the program asks user to enter the following two quantities via keyboard: Length of the random string that will be used in the rest of the program it is an integer in the legal range of thousand inclusive to billion inclusive Maximum length of the special patterns that the program looks for it is an integer in the legal range of inclusive to inclusive If the user does not enter each of the above values within the legal range, the main method needs to throw a NumberFormatException in a try block. The exception must be caught in the main method by requesting the the user to try again see the starter code posted on Canvas for more details Random String Generation In the second step, the program uses java.util.Random.nextIntint bound method to generate a random string made of a sequence of randomly generated lowercase letters. The above private static String randomStringGeneratorint length Random random new RandomSystemnanoTime; char array new charlength; for int i ; i length; i arrayichara random.nextInt; return new Stringarray; method, which is called by the main method, generates a random string with a given length. This string is only made of lowercase letters in the alphabet. Finding Special Patterns In the third step, the program uses Exception Handling to find the longest mostinterestingspecial pattern in the generated random string. The program is interested in finding one of the following special patterns: I. Singleton string: A singleton string is made of only one letter. Examples: mmmmm qqqqqqq rr s yyy II Arithmetic String of Order : A string made of subsequent alphabetical letters that appear in the alphabetical order. Examples: bcdef, pqrstuvwx, jk y III. Arithmetic String of Order : A string made of subsequent alphabetical letters that appear in the reverse alphabetical order. Example: fedcb, xwvutsrqp, kj y IV Balanced Tripartite String: A string made of three identical parts. Example: busbusbus, laptoplaptoplaptop, zzz V Balanced Bipartite String: A string made of two identical halves. Examples: ticktick, hophop, tantan nocknock, nn VI Palindrome: A palindrome reads the same backward as forward. Examples: abcba, bob, g Please note that the above list is ranked in the decreasing order of their rarity. If there are two interesting patterns of the same length in the random string, the program needs to report the more infrequent one! For example, consider the following random string: thisisarandomstringbobbobbobendof thestring In this string, there is a palindrome of length bobbobbob and a balanced tripartitie of the same length bobbobbob The program reports the latter one as it is higher in the rank of special patterns. As another example, consider the following random string: yyyyyyyyycdefghijkl In this string, there is a sinleton string of length yyyyyyyyy and an arithmetic string of order with length cdefghijkl The program reports the latter one as it is longer. When reporting the special pattern, the program needs to specify the actual pattern cdefghijkl and the index of its occurrence Required Exception Classes To implement the third step of the program, you need to first define one exception class for each special pattern and then throw an instance of it once you find the pattern in the random string. For example, the following exception is defined to handle singleton strings: An instance of this exception is constructed and thrown once it is found in the random
PARTIAL CODE
PATTERNFINDER CLASS
package main;
import util.;
import java.util.;
public class PatternFinder
private static String randomStringGeneratorint length generates a string made of randomly generated lowercase
letters.
Random random new RandomSystemnanoTime;
char array new charlength;
for int i ; i length; i
arrayichara random.nextInt;
return new Stringarray;
private static void singletonMinerString mine, int length throws SingletonException
for int start ; start mine.length length; start
int i;
for i start ; i start length; i
if minecharAti mine.charAti
break;
if i start length
throw new SingletonExceptionminesubstringstart start length start;
public static void mainString args
Scanner keyboard new ScannerSystemin;
Step : handling input...
System.out.printlnEnter the length of random string: ;
int randomS
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
