import java.io.*; //For File class and FileNotFoundException
import java.util.Scanner; //For Scanner class
/** A program to generate random, pronounceable passwords.
*/
public class Homework12
{
public static void main(String[] args)
{
/** Declare and initialize four arrays: vowels, consonants, two types of
consonant clusters. */
String[] vowel = {"a", "e", "i", "o", "u"};
String[] consonant = {"b", "c", "d", "f", "g", "h", "j", "k", "l", "m",
"n", "p", "q", "r", "s", "t", "v", "w", "x", "y",
"z"};
String[] cluster_start = new String[84];
String[] cluster_end = new String[37];
/** Use the first file, which contains consonant clusters
typically used to begin words in English, to populate array cluster_start[]. */
try
{
//Open the file
File file = new File("consonantclusters_start.txt");
Scanner inputFile = new Scanner(file);
//Read from the file
int index;
for (index = 0; index < 83; index++)
{
cluster_start[index] = inputFile.next();
}
}
catch (FileNotFoundException e)
{
System.out.println("File not found.");
}
/** Use the second file, which contains consonant clusters
typically used to end words in English, to populate array cluster_end[]. */
try
{
//Open the file
File file2 = new File("consonantclusters_end.txt");
Scanner inputFile = new Scanner(file2);
//Read from the file
int index;
for (index = 0; index < 36; index++)
{
cluster_end[index] = inputFile.next();
}
}
catch (FileNotFoundException e)
{
System.out.println("File not found.");
}
/** Generate random numbers within the length ranges of each array, use
those numbers to pick index locations from the arrays, and String those
locations' values together to form the passwords. Repeat (and print) 10x.
*/
for (int counter = 1; counter <= 10; counter++)
{
int randCluster = (0 + (int)(Math.random() * ((83-0) + 1)));
int randVowel = (0 + (int)(Math.random() * ((4-0) + 1)));
int randConsonant = (0 + (int)(Math.random() * ((20-0) + 1)));
int randVowel2 = (0 + (int)(Math.random() * ((4-0) + 1)));
int randCluster2 = (0 + (int)(Math.random() * ((36-0) + 1)));
int randVowel3 = (0 + (int)(Math.random() * ((4-0) + 1)));
int randCluster3 = (0 + (int)(Math.random() * ((36-0) + 1)));
String bit1 = cluster_start[randCluster];
String bit2 = vowel[randVowel];
String bit3 = consonant[randConsonant];
String bit4 = vowel[randVowel2];
String bit5 = cluster_end[randCluster2];
String bit6 = vowel[randVowel3];
String bit7 = cluster_end[randCluster3];
System.out.println(bit1 + bit2 + bit3 + bit4 + bit5 + bit6 + bit7);
}
}
}