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]);
}
}
}