Basically I have no idea what I did wrong here. The assignment:

Write a program to do the following:
Prompt for input of someone's first, middle, and last name as a single string (using any combination of upper and lowercase letters).
Check to make sure the name was entered in the correct format (3 names separated by spaces). If the input is not correct, continue to request the input again until the format is correct.
Capitalize only the first letters of each part of the name, and print out the revised name.
Print out the initials for that name.
Print out the name in the format of: Lastname, Firstname, MI. (for example: Smith, John A.).

Note: You must use the substring method, and you cannot utilize arrays or use StringTokenizer to accomplish this.



Code:
    import java.util.*;
public class Name 
{
	public static void main(String[] args) 
	{
		
		Scanner input = new Scanner (System.in);
	
		int stringLength;
		int blankSpace = 0;
		boolean good = false;
		
			while (!good)
			{
				System.out.print("Enter your name as 'First Middle Last': ");
				String aString = input.nextLine();
				stringLength = aString.length();
				
				blankSpace = 0;
				for (int i = 0; i < stringLength; i++)
				{
					aString.charAt(i);
					char ch = (aString.charAt(i));
					
					if (ch == ' ')
						{	
							blankSpace++;
						}	
					}
					
					if (blankSpace == 2)
						{
							good = true;
						}
					
					else
						System.out.println("Invalid input");	
			}
		
		int index = 0;
		String firstName = "";
		String middleName = "";
		String lastName = "";
		String aString = "";
		char ch = ' ';
		
		while (aString.charAt(index)!= ' ')
		{
			firstName = firstName + aString.charAt(index);
				++index;
		}
		
		ch = Character.toUpperCase(firstName.charAt(0));
		firstName = ch+ firstName.substring(1, firstName.length());
		
		aString = aString.substring(index + 1);
		index = 0;
		
		while (aString.charAt(index)!= ' ')
		{
			middleName = middleName + aString.charAt(index + 1);
				++index;
		}
	
		ch =  Character.toUpperCase(middleName.charAt(0));
		middleName = ch + middleName.substring(1, middleName.length());
		
		lastName = aString.substring(index + 1);
		ch = Character.toUpperCase(lastName.charAt(0));
		lastName = ch + lastName.substring(1, lastName.length());
			
		
		System.out.println("\nYou entered: " + firstName + middleName + lastName);
		
		System.out.println("\nYour initials are: " + firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0));
		
		System.out.println("Displayed with last name first: " + lastName + ", " + firstName + middleName.charAt(0));
			
	}

}
The error message I get:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(Unknown Source)
at Name.main(Name.java:47)

Any help would be appreciated.