Please take a look at the class below.. it does not quite match the homework
.. but you should be able to get the idea of what I was trying to do
I am sure we can specify and use Key=>Value pairs here to optimize this ....
but I am not at the point where I can use it.

Cheers
Dasa

public class LongestLastName {

/**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
int FamilyMembers = 4;
 String FamilyMemberNames[] = new String[FamilyMembers];
String FirstNames[] = new String[FamilyMembers];
String LastNames[] = new String[FamilyMembers];
String nameArray[] = new String[2];
String msg;
int nameLength = 0;
int FirstNamesLength[] = new int[FamilyMembers];
int LastNamesLength[] = new int[FamilyMembers];
int IndexOfHighestLength=0;
int LengthOfName=0;
 for (int i = 0; i < FamilyMembers; i++){
do{
FamilyMemberNames[i] = JOptionPane.showInputDialog("enter "+ FamilyMembers+"
names as \"FirstName LastName\"");
 try {
nameLength=FamilyMemberNames[i].split(" ").length;
} catch (Exception e) {
msg="Names should be in \"FirstName LastName\" Format";
JOptionPane.showMessageDialog(null, msg);
}
}while (nameLength != 2);
}
 for (int j=0; j<FamilyMemberNames.length; j++){
    nameArray=FamilyMemberNames[j].split(" ");
    FirstNames[j]=nameArray[0];
    LastNames[j]=nameArray[1];
}
 for (int i=0; i<FirstNames.length;i++){
FirstNamesLength[i]=FirstNames[i].length();
 if ((i==0)||(LengthOfName<FirstNamesLength[i])){
IndexOfHighestLength=i;
LengthOfName = FirstNamesLength[i];
}
}
msg="The longest First name is "+FirstNames[IndexOfHighestLength]+". Its
length is "+FirstNamesLength[IndexOfHighestLength];
System.out.println(msg);
 LengthOfName=0;
IndexOfHighestLength=0;
 for (int i=0; i<LastNames.length;i++){
LastNamesLength[i]=LastNames[i].length();

if ((i==0)||(LengthOfName<LastNamesLength[i])){
IndexOfHighestLength=i;
LengthOfName = LastNamesLength[i];
}
}
msg="The longest last name is "+LastNames[IndexOfHighestLength]+". Its
length is "+LastNamesLength[IndexOfHighestLength];
System.out.println(msg);
}

}


On Thu, Nov 13, 2008 at 9:14 AM, suganthi m <[EMAIL PROTECTED]> wrote:

> Please anyone help to do the Homework exercise  MyOwnJavaArrayProject
> under *Java Array (jedi, 1.07)
> *
> >
>

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to