COP-3337 Programming II Programming Assignment 4 FIU Knight Foundation School of Computing & Information Sciences For this programming assignment, you will implement of a java program that generates a...

1 answer below »
Assingments specifications in files. (PA4 is the specifications of the assignment, and the "PA4 Draft.zip" is a starter code given by the professor.



COP-3337 Programming II Programming Assignment 4 FIU Knight Foundation School of Computing & Information Sciences 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. 1 Flow of the Program 1.1 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 100 thousand (inclusive) to 1 billion (inclusive)), ˆ Maximum length of the special patterns that the program looks for (it is an integer in the legal range of 3 (inclusive) to 15 (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). 1.2 Random String Generation In the second step, the program uses java.util.Random.nextInt(int bound) method to generate a random string made of a sequence of randomly generated lowercase letters. The above 1 private static String randomStringGenerator(int length) { 2 Random random = new Random(System.nanoTime()); 3 char[] array = new char[length]; 4 for (int i = 0; i < length;="" i++)="" 5="" array[i]="(char)" (’a’="" +="" random.nextint(26));="" 6="" return="" new="" string(array);="" 7="" }="" 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.="" 1="" 1.3="" finding="" special="" patterns="" in="" the="" third="" step,="" the="" program="" uses="" “exception="" handling”="" to="" find="" the="" longest="" most-interesting/special="" pattern="" in="" the="" generated="" random="" string.="" the="" program="" is="" interested="" in="" finding="" one="" of="" the="" fol-="" lowing="" 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="" 1:="" a="" string="" made="" of="" subsequent="" alphabetical="" letters="" that="" appear="" in="" the="" alphabetical="" order.="" examples:="" bcdef,="" pqrstuvwx,="" jk,="" y="" iii.="" arithmetic="" string="" of="" order="" -1:="" 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:="" bus-="" busbus,="" laptoplaptoplaptop,="" zzz="" v.="" balanced="" bipartite="" string:="" a="" string="" made="" of="" two="" identical="" halves.="" examples:="" tick-="" tick,="" 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:="" thisisarandomstringbobbobbobendofthestring="" in="" this="" string,="" there="" is="" a="" palindrome="" of="" length="" 9="" (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="" 9="" (yyyyyyyyy)="" and="" an="" arithmetic="" string="" of="" order="" 1="" with="" length="" 10="" (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="" (9).="" 2="" 2="" 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="" 1="" public="" class="" singletonexception="" extends="" exception="" {="" 2="" private="" string="" singletonstring;="" 3="" private="" int="" occurrenceindex;="" 4="" @override="" 5="" public="" string="" getmessage()="" {="" 6="" return="" singletonstring="" +="" ”="" is="" a="" singleton="" string="" that="" is="" found="" at="" index="" ”="" +="" occurrenceindex="" +="" ”!”;="" 7="" }="" 8="" public="" singletonexception(string="" singletonstring,="" int="" index)="" {="" 9="" this.singletonstring="singletonString;" 10="" occurrenceindex="index;" 11="" }="" 12="" }="" string.="" the="" following="" static="" method="" is="" responsible="" for="" finding="" the="" singleton="" patterns:="" the="" 1="" private="" static="" void="" singletonminer(string="" mine,="" int="" length)="" throws="" singletonexception{="" 2="" for="" (int="" start="0;" start="">< mine.length()="" -="" length;="" start++)="" {="" 3="" int="" i;="" 4="" for="" (i="start" +="" 1;="" i="">< start="" +="" length;="" i++)="" 5="" if="" (mine.charat(i)="" !="mine.charAt(i" -="" 1))="" 6="" break;="" 7="" if="" (i="=" start="" +="" length)="" 8="" throw="" new="" singletonexception(mine.substring(start,="" start="" +="" length),="" start);="" 9="" }="" 10="" }="" exception="" thrown="" by="" the="" method="" singletonminer="" is="" caught="" by="" the="" following="" try-catch="" block="" that="" appears="" in="" the="" main="" method:="" 1="" patternmaxlength="5;//the" max="" length="" of="" pattern="" is="" given="" by="" user="" via="" keyboard!="" 2="" string="" randomstring="randomStringGenerator(randomStringLength);" 3="" try="" {="" 4="" for="" (int="" length="patternMaxLength;" length=""> 0; length−−) 5 singletonMiner(randomString, length); 6 } catch (Exception exp) { 7 System.out.println(exp.getMessage()); 8 } 3 Submissions You need to submit a .zip file compressing the packages containing all the java source files related to the assignment (.java files). 3
Answered 1 days AfterMar 20, 2022

Answer To: COP-3337 Programming II Programming Assignment 4 FIU Knight Foundation School of Computing &...

Kshitij answered on Mar 21 2022
108 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here