a program that will accept a String, containing only alphanumerical characters, from the user and try to match that String by repeatedly generating and comparing alphanumerical StringsThis is similar to the Die Face Sequence project you did as homework. The key difference with this problem is that the randomly generated test String, in this problem, is built as a set instead of as a rolling sequence. This means that you build the entire test string using randomly generated alphanumeric characters, then test to see if it is equal to the user entered target string. Continue generating new Strings until the Strings are equal. Display how many random character Strings were generated until a matching String was found. You must allow the user to repeat the program as many times as they would like. Ensure that the user only enters valid input for any user input.
Key requirements:
build a MyStrings class with 2 methods randomAlphanumericString(int):String that returns a String of random alphanumerical characters of the length received from the integer argument. The general nature of alphanumeric characters can be found in the ASCII table.
validAlphanumericString(String):boolean that returns true when the String argument only contains alphanumeric characters. included FindAlphanumericTester class that accepts only alphanumeric Strings from the user calls validAlphanumericString() from the MyStrings class to check for valid user input calls randomAlphanumericString from the MyStrings class to generate a random alphanumeric String displays the number of attempts required to generate a matching String allows the user to repeat the program as many times as they wish. validates all user input restricts user input to specific choices (This means that you may not ask the user to enter yes or no and then only check for a yes answer and assume any other answer is no.) Include the IPO and Algorithm solutions for this problem. Each method must have its own algorithm Output: Please enter an alphanumeric string of characters. R2@2 "R2@2" contains non alphanumeric characters. Please enter an alphanumeric string of characters. R2d2 It took 1,423,622 random generations of an alphanumeric String to generate the 4 character String "R2d2" Would you like to try another alphanumeric string of characters? Please enter "y" for yes and "n" for no no Please enter "y" for yes and "n" for no b Please enter "y" for yes and "n" for no y Please enter an alphanumeric string of characters. 7rtH3erfGJJ A string that long might take a while to randomly generate. Would you like to go ahead and try this string? Please enter "y" for yes and "n" for no no Please enter "y" for yes and "n" for no b Please enter "y" for yes and "n" for no y It took 11,324,423,622 random generations of an alphanumeric String to generate the 9 character String "7rtH3erfGJJ" Would you like to try another alphanumeric string of characters? Please enter "y" for yes and "n" for no n Goodbye!!
Aucun commentaire:
Enregistrer un commentaire