Reference no: EM132399202
If a 3-Dimensional array is defined by the following statement where the first level (dimension) contains the pages, the second level contains the paragraphs in each page, and the third level contains the lines in each paragraph:
final String [ ] [ ] [ ] book = {
{//text 1} , { //text 2} , {//text3} }
What is the Java code that will generate a password from this array respecting the following restrictions:
1. A password is composed of three words.
2. The page number, paragraph number, and line number are chosen randomly. You must use the java.util.Random class to generate random numbers using the nextInt() method.
3. Convert the String from the chosen line into an array of words using the split(" ") method (space as the separator).
4. Choose a random word from the array in Step 3. (Hint: the length attribute of an array will tell you how many words are in the array.)
5. If a word is composed of only a single character (e.g., "a"), or the word contains the newline character ('n'), go back to Step 2.
6. When you have three words, concatenate them to form a candidate password, and apply the following steps. You can use the compareTo() method from the String class
(but no HashSet). Restriction: Don't use any method from the Character class.
a. No two words can be exactly the same (e.g., "theAlicethe" isn't allowed, but "the" and "The" are accepted). Otherwise, go back to Step 2.
b. The password must be of at least 8 characters long but under 16 characters. Otherwise, go back to Step 2.
c. The password must contain an uppercase character. Otherwise, go back to Step 2.
d. The password must contain a lowercase character. Otherwise, go back to Step 2.
e. The password must contain only one special (non-alphabetic) character. Otherwise, go back to Step 2. Restriction: Don't use any method from the Character class.
f. If all conditions are met, you print the password, along with the number of password generation attempts that failed due to: (i) having a newline character, (ii) having a single.
character word, (iii) having the same words, (iv) not meeting the uppercase requirement, (v) not meeting the lowercase requirement, (vi) not meeting the special character.
Requirement.
7. You continue generating passwords until you generate a total of 10,000 passwords, OR if you generate a password where the count for item (v) in Step 6 f) is non-zero.