Below are the instructions for what I am currently working on. I am having 2 problems first is printing the values stored in my array right now i have it set up in a for loop but there seems to be something wrong with the syntax of my System.out statement that I'm not getting.

for(int index=0; index<5; index++)

{
System.out.println (UserName[index]" "+UserID[index]);

}

My second issue is that when I remove my output then I can compile the class file except when I run it I get a string index out of bounds error and I'm not sure what I'm doing wrong.

Write a program that does the following for five names:

1. Prompts the User to enter First Name.
2. Prompts the User to enter Last Name.
3. Creates a User ID of the first seven letters of the User's Last Name and the first letter of the User's First Name. The ID will be ALL LOWER CASE letters.
4. If the Input is as follows:

Alexander Fenstermaker
FRED FERGEL
SaLLy Gnashes
patrick fitzpatrick
Yetzel BYRD

Then Output the User ID's along with the User's First and Last Name as follows:

User Name User ID
*******************************
Fenstermaker, Alexan fenstera
Fergel, Fred fergelf
Gnashes, Sally gnashess
Fitzpatrick, Patri fitzpatp
Byrd, Yetzel byrdy

NOTE: You must include the caption.

 Make sure the User Name is printed with a Capital (UPPER CASE) letter for the first letter of the first and last name.
 Make sure that the rest of the name is all lower case.
 All User Names will be printed on a field width of 20.
o This will include the comma and the space between the first and last name.
o For example, Alexander Fenstermaker's name is longer than 20 characters. You must include a comma and a space between the first and last name so you can only use 18 characters of the full name.
 You must leave at least two spaces between the User Name and the User ID.
 You must use arrays.
o Store the concatenated first and last name in an array.
o Store the User ID created for the User in another array.
o Make sure the corresponding array indexes match.
o For example, the name stored in the Name Array at index 2 must correspond with the User ID stored in the ID Array at index 2.

//Prologue Section
/**********************************************************************
*Program Name:   CSC 111 Program 2
*Author:    Peter Welch
*Date:     2/28/11
*Course/Section:  CSC 111-001 (002w)
*Program Description:  Program designed to output a user name and userID based on first name and last name input by user.
*
*Initial Algorithm:
*
*BEGIN Program 2
*
*User input – FirstName
*User input – LastName
*User Name stored in array
*UserID stored in array
*Print formatted user names and userID
*
*END Program 2
 *********************************************************************/

 //Pre-Processor Declaration Section

 public class Welch_Program2 // begin class definition
 {


	 public static void main (String[] args)
	 {




		 for(int index=0; index<5; index++) //begin for loop

		 {
			 String FirstName, FN1, FN2, FN3, FN4, LastName, LN1, LN2, LN3, LN4, FullName, ID;

			 String [] UserName = new String[5];

		     String [] UserID = new String[5];

			 int endindex1, endindex2;



			 System.out.println ("Enter first name. "); /*Gets first name and formats for UserName*/

			 FirstName = Keyboard.readString();

			 FN1 = FirstName.toLowerCase();

			 FN2 = FN1.substring(0,1);

			 FN3 = FN2.toUpperCase();

			 endindex1 = FirstName.length();

			 FN4 = FN3+FN1.substring(1,endindex1);




			 System.out.println ("Enter last name. "); /*Gets last name and formats for UserName*/

			 LastName = Keyboard.readString();

			 LN1 = LastName.toLowerCase();

			 LN2 = LN1.substring(0,1);

			 LN3 = LN2.toUpperCase();

			 endindex2 = LastName.length();

			 LN4 = LN3+LN1.substring(1,endindex2);




			 // prepares values to be stored in index

			 FullName = LN4+", "+FN4;


			 ID = LN1.substring(0,7)+FN2.toLowerCase();



			 // Places values in corrisponding arrays


			UserName[index] = FullName.substring(0,20);


			UserID[index] = ID;

		 } // end for loop

			 // Display Header for output

			 System.out.println("		USER NAME			USERID			");
			 System.out.println("*******************************************");


	for(int index=0; index<5; index++)

	{
		System.out.println (UserName[index]"   "+UserID[index]); 

	}
  }
}

1. Your print expression has one correct + operator, but it needs two!
2. You define and create your arrays inside the loop, so each iteration of the loop creates and destroys a new set of arrays. You need to define and create them before starting the loop so that each iteration of the loop is working with the same arrays.

Hi, edited post
Sorry, maybe he didn't read my answer I forgot to refresh the page and didn't saw your reply.

Hello Hertze. I deliberately didn't give the OP the exact fix to his code so that he would work it out for himself and learn. So you give him the exact fix to copy/paste and what does he learn? Please remember that we are trying to help people to learn Java, not to help them cheat their homework

have made the suggested changes and the file will compile with out any syntax errors but I'm still getting this message when i run the class file

Exception in thread "main" java.lang.StringIndexOutOfBoundException: String index out of range: 7

at java.lan.String.substring(String.java:1934)
at welch_Program2.main(welch_program2.java:91)

below is my modified code with the changes I made

//Prologue Section
/**********************************************************************
*Program Name:   CSC 111 Program 2
*Author:    Peter Welch
*Date:     2/28/11
*Course/Section:  CSC 111-001 (002w)
*Program Description:  Program designed to output a user name and userID based on first name and last name input by user.
*
*Initial Algorithm:
*
*BEGIN Program 2
*
*User input – FirstName
*User input – LastName
*User Name stored in array
*UserID stored in array
*Print formatted user names and userID
*
*END Program 2
 *********************************************************************/

 //Pre-Processor Declaration Section

 public class Welch_Program2 // begin class definition
 {




	 public static void main (String[] args)
	 {

 				 String [] UserName = new String[5];

	 		     String [] UserID = new String[5];





		 for(int index=0; index<5; index++) //begin for loop

		 {

			String FirstName, FN1, FN2, FN3, FN4, LastName, LN1, LN2, LN3, LN4, FullName, ID;


			 int endindex1, endindex2;



			 System.out.println ("Enter first name. "); /*Gets first name and formats for UserName*/

			 FirstName = Keyboard.readString();

			 FN1 = FirstName.toLowerCase();

			 FN2 = FN1.substring(0,1);

			 FN3 = FN2.toUpperCase();

			 endindex1 = FirstName.length();

			 FN4 = FN3+FN1.substring(1,endindex1);




			 System.out.println ("Enter last name. "); /*Gets last name and formats for UserName*/

			 LastName = Keyboard.readString();

			 LN1 = LastName.toLowerCase();

			 LN2 = LN1.substring(0,1);

			 LN3 = LN2.toUpperCase();

			 endindex2 = LastName.length();

			 LN4 = LN3+LN1.substring(1,endindex2);




			 // prepares values to be stored in index

			 FullName = LN4+", "+FN4;


			 ID = LN1.substring(0,7)+FN2.toLowerCase();



			 // Places values in corrisponding arrays


			UserName[index] = FullName.substring(0,20);


			UserID[index] = ID;

		 } // end for loop

			 // Display Header for output

			 System.out.println("		USER NAME			USERID			");
			 System.out.println("*******************************************");


	for(int index=0; index<5; index++)

	{
		System.out.println (UserName[index]+"   "+UserID[index]);

	}
  }
}

Guess what happens here when 'LN1' has less than 7 characters?

LN1.substring(0,7)

Thanks for helping find the solution guys here's the working code :)

//Prologue Section
/**********************************************************************
*Program Name:   CSC 111 Program 2
*Author:    Peter Welch
*Date:     2/28/11
*Course/Section:  CSC 111-001 (002w)
*Program Description:  Program designed to output a user name and userID based on first name and last name input by user.
*
*Initial Algorithm:
*
*BEGIN Program 2
*
*User input – FirstName
*User input – LastName
*User Name stored in array
*UserID stored in array
*Print formatted user names and userID
*
*END Program 2
 *********************************************************************/

 //Pre-Processor Declaration Section

 public class Welch_Program2 // begin class definition
 {




	 public static void main (String[] args)
	 {

 				 String [] UserName = new String[5];

	 		     String [] UserID = new String[5];





		 for(int index=0; index<5; index++) //begin for loop

		 {

			String FirstName, FN1, FN2, FN3, FN4, LastName, LN1, LN2, LN3, LN4, FullName, ID;


			 int endindex1, endindex2;



			 System.out.println ("Enter first name. "); /*Gets first name and formats for UserName*/

			 FirstName = Keyboard.readString();

			 FN1 = FirstName.toLowerCase();

			 FN2 = FN1.substring(0,1);

			 FN3 = FN2.toUpperCase();

			 endindex1 = FirstName.length();

			 FN4 = FN3+FN1.substring(1,endindex1);




			 System.out.println ("Enter last name. "); /*Gets last name and formats for UserName*/

			 LastName = Keyboard.readString();

			 LN1 = LastName.toLowerCase();

			 LN2 = LN1.substring(0,1);

			 LN3 = LN2.toUpperCase();

			 endindex2 = LastName.length();

			 LN4 = LN3+LN1.substring(1,endindex2);




			 // prepares values to be stored in index

			 FullName = LN4+", "+FN4;


			 if (LN1.length()<7)

			 ID = LN1 + FN2.toLowerCase();

			 else


			 ID = LN1.substring(0,7)+FN2.toLowerCase();



			 // Places values in corrisponding arrays
			if (FullName.length()<20)
			UserName[index] = FullName;

			else

			UserName[index] = FullName.substring(0,20);


			UserID[index] = ID;

		 } // end for loop

			 // Display Header for output

			 System.out.println("		USER NAME	   USERID			");
			 System.out.println("		*********************");


	for(int index=0; index<5; index++)

	{
		System.out.println ("		"+UserName[index]+"  	 "+UserID[index]);

	}
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.