/*
 *  Name: Jeff
 *  Assignment: 3 BONUS PROGRAM
 *  Purpose: Create a Java program to generate passwords based on individual user input.
 *  These inputs consist of the prospective users first, middle, and last names,
 *  and also a 4 digit number of their choosing. The password is all lower case,
 *  and is of the format: f m l d d d d
 *  Where f is the first letter of the first name,
 *  m is the last letter of the middle name,
 *  l is the first letter of the last name,
 *  and d d d d is the 4 digit number entered by the user.
 *  The program is ended when the user enters "QUIT" as a first name.
 *
 */

/**
 *  Description of the Class
 *
 *@author     jeff
 *@created    May 15, 2003
 */
public class Password {
	/**
	 *  The main program for the Password class
	 *
	 *@param  args  The command line arguments
	 */
	public static void main(String[] args) {
		System.out.println("You need a password.\nYou may obtain as many passwords as you need here.\nWhen you are finished, enter \"QUIT\" (all capital letters)\nas a first name.");
		ConsoleReader cr = new ConsoleReader(System.in);
		// Imports the Console Reader.
		boolean firstNameQuit;
		// Establishes a boolean variable to help determine when to quit the program.
		int numPasswds = 0;
		// Counts the number of passwords generated.
		String quit = "QUIT";
		// Helps decide when to quit the program.
		String firstName;
		// Establishes a variable for the first name of the user.
		System.out.print("\tPlease enter your first name: ");
		// Asks for the first name.
		firstName = cr.readLine();
		//Retrieves the first name from the Console Reader.
		firstNameQuit = (firstName.equals(quit));
		// In effect, checks to see if the program should be ended.
		while (firstNameQuit == false) {
			// If the program should not be ended then continue until "quit" is entered as a first name.


			String middleName;
			System.out.println("If you do not have a middle name, please provide your \"Fantasy\" middle name.");
			System.out.print("\tPlease enter your middle name: ");
			middleName = cr.readLine();
			// Asks for and retrieves the middle name.
			String lastName;
			System.out.print("\tPlease enter your last name: ");
			lastName = cr.readLine();
			String number;
			System.out.print("\tPlease enter any four digit number: ");
			number = cr.readLine();
			// Asks for and retrieves the last name ant the 4 digit number.
			String firstInitial = firstName.substring(0, 1);
			// Gets the first initial.

			int middleSize = middleName.length();
			// Counts the number of letters in the middle name.
			String middleInitial = middleName.substring(middleSize - 1, middleSize);
			// Gets the last letter of the middle name for the password.
			String lastInitial = lastName.substring(0, 1);
			numPasswds++;
			// Keeps track of the number of passwords created.
			String password = firstInitial.toLowerCase() + middleInitial.toLowerCase() + lastInitial.toLowerCase() + number;
			// Creates password.
			System.out.println("\tYour new password is: " + password);
			// Prints password.

			System.out.print("\tPlease enter your first name: ");
			//Starts over.
			firstName = cr.readLine();
			firstNameQuit = (firstName.equals(quit));
			// Checks to see if the user wants to quit.

		}

		System.out.println("You are finished!");
		// If someone enters "quit" as a first name, the program skips here and finishes up.
		System.out.println("You have generated " + numPasswds + " passwords.\n\t Thank You!");
	}

}


