Dear Friends ,
Prof. Shin has devised a Lab Exercise quite detailed than it shows, I
communicate my solution
in an hope that will enlighten the way I followed for having a
complete solution. I  hope that will be useful....

import javax.swing.JOptionPane;

public class TestNames1 {

        /**
         * @param args
         */
        public static void main(String[] args) {
                String[] names = new String[3];
                String[] m = new String[3];
                char t = 32;
                Boolean test1 = false;
                Boolean test2 = false;
                Boolean test3 = false;

                names[0] = JOptionPane.showInputDialog("Enter First Name ");
                names[1] = JOptionPane.showInputDialog("Enter Second Name ");
                names[2] = JOptionPane.showInputDialog("Enter Third Name ");

                for (int i = 0; i < 3; i++) {
                        m[i] = "";
                }
                for (int i = 0; i < names.length; i++) {
                        for (int j = 0; j < names[i].length(); j++) {
                                if (names[i].charAt(j) != t) {
                                        m[i] = m[i] + names[i].charAt(j);
                                } else
                                        break;
                        }

                }

                test1 = m[0].length() == m[1].length();
                test2 = m[1].length() == m[2].length();
                test3 = m[0].length() == m[2].length();


                if (test1 && test2) {
                        // All Three Names Are Equal
                        JOptionPane.showMessageDialog(null,
                                        "These All Three Names Are Equal in 
Length   :   " + m[0]
                                                        + " " + m[1] + " " + 
m[2]);
                }

                if (test1 && !test2) {

                        // First two Names Are Equal Remaining is Different

                        if (m[0].length() > m[2].length()) {
                                JOptionPane
                                                .showMessageDialog(
                                                                null,
                                                                "From These 
Three Names The First Two Are Equal in Length The
Third is Different, The Longest is The First and Second :  "
                                                                                
+ m[0]
                                                                                
+ " "
                                                                                
+ m[1]
                                                                                
+ "   the Third is Shorter :   " + m[2]);
                        } else {
                                JOptionPane
                                                .showMessageDialog(
                                                                null,
                                                                "From These 
Three Names The First Two Are Equal in Length The
Third is Different, The Longest is The Third  : "
                                                                                
+ m[2]
                                                                                
+ "     The First and Second Are Shorter :  "
                                                                                
+ m[0] + " " + m[1]);
                        }
                }

                if (test2 && !test3) {

                        // First Name is Different Second and Third are Equal

                        if (m[0].length() > m[2].length()) {
                                JOptionPane
                                                .showMessageDialog(
                                                                null,
                                                                "From These 
Three Names The First is Different, Remaining Two
Are Equal in Length , The Longest is The First :  "
                                                                                
+ m[0]
                                                                                
+ "   The Second and The Third are Shorter  : "
                                                                                
+ m[1] + "   " + m[2]);
                        } else {
                                JOptionPane
                                                .showMessageDialog(
                                                                null,
                                                                "From These 
Three Names The First is Different, Remaining Two
Are Equal in Length , The Longer are The Second and The Third :  "
                                                                                
+ m[1]
                                                                                
+ "   "
                                                                                
+ m[2]
                                                                                
+ "  The First is Shorter :  " + m[0]);
                        }

                }
                if (test3 && !test2) {

                        // Second Name is Different First and Third are Equal

                        if (m[0].length() > m[1].length()) {
                                JOptionPane
                                                .showMessageDialog(
                                                                null,
                                                                "From These 
Three Names The Second is Different, Remaining Two
i. e First and Last Are Equal in Length , The Longer are The First and
Last  :  "
                                                                                
+ m[0]
                                                                                
+ "   "
                                                                                
+ m[2]
                                                                                
+ "   The Second  is Shorter  : "
                                                                                
+ m[1]);
                        } else {
                                JOptionPane
                                                .showMessageDialog(
                                                                null,
                                                                "From These 
Three Names The Second is Different, Remaining Two
i. e First and Last Are Equal in Length , The Longest is The
Second  :  "
                                                                                
+ m[1]
                                                                                
+ "  The First and The Last are  Shorter :  "
                                                                                
+ m[0] + "  " + m[2]);
                        }

                }

                if (!test1 && !test2 && !test3) {

                        // All Names Are Different Respectively

                        if (names[0].length() > names[1].length()
                                        && (names[0].length() > 
names[2].length())) {
                                if (names[1].length() > names[2].length()) {
                                        JOptionPane
                                                        .showMessageDialog(
                                                                        null,
                                                                        " The 
Longest Name is The First  :  "
                                                                                
        + m[0]
                                                                                
        + "  The Second Longer Name is The Second :  "
                                                                                
        + m[1]
                                                                                
        + "  The Shortest Name is The Third : "
                                                                                
        + m[2]);
                                } else {
                                        JOptionPane
                                                        .showMessageDialog(
                                                                        null,
                                                                        " The 
Longest Name is The First  :  "
                                                                                
        + m[0]
                                                                                
        + "  The Second Longer Name is The Third :  "
                                                                                
        + m[2]
                                                                                
        + "  The Shortest Name is : The Second "
                                                                                
        + m[1]);
                                }
                        }

                        if (names[1].length() > names[0].length()
                                        && (names[1].length() > 
names[2].length())) {
                                if (names[0].length() > names[2].length()) {
                                        JOptionPane
                                                        .showMessageDialog(
                                                                        null,
                                                                        " The 
Longest Name is The Second  :  "
                                                                                
        + m[1]
                                                                                
        + "  The Second Longer Name is The First :  "
                                                                                
        + m[0]
                                                                                
        + "  The Shortest Name is The Third : "
                                                                                
        + m[2]);
                                } else {
                                        JOptionPane
                                                        .showMessageDialog(
                                                                        null,
                                                                        " The 
Longest Name is The Second  :  "
                                                                                
        + m[1]
                                                                                
        + "  The Second Longer Name is The Third :  "
                                                                                
        + m[2]
                                                                                
        + "  The Shortest Name is : The First "
                                                                                
        + m[0]);
                                }
                        }
                        if (names[2].length() > names[0].length()
                                        && (names[2].length() > 
names[1].length())) {
                                if (names[0].length() > names[1].length()) {
                                        JOptionPane
                                                        .showMessageDialog(
                                                                        null,
                                                                        " The 
Longest Name is The Third  :  "
                                                                                
        + m[2]
                                                                                
        + "  The Second Longer Name is The First :  "
                                                                                
        + m[0]
                                                                                
        + "  The Shortest Name is The Second : "
                                                                                
        + m[1]);
                                } else {
                                        JOptionPane
                                                        .showMessageDialog(
                                                                        null,
                                                                        " The 
Longest Name is The Third  :  "
                                                                                
        + m[2]
                                                                                
        + "  The Second Longer Name is The Second :  "
                                                                                
        + m[1]
                                                                                
        + "  The Shortest Name is : The First "
                                                                                
        + m[0]);
                                }
                        }
                }

        }

}

-- 
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