Hi all,
I wrote this program for constructing an ID out of someones first name, middle name, last name, and address. I got it to work and run perfectly except for one small thing. There is suppose to be the possibility for the person to not enter a middle name, but when i tried not entering a middle name when i ran it the last message dialog box didnt pop-up as it does if the middle name is entered. Is there something i can do so that if a middle name is not entered that it just ignores that it is not there? I was thinking of adding validation to make sure a first and last name is entered. Heres my code:
import javax.swing.*;
public class ConstructID
{
public static void main(String [] args)
{
String firstName = "";
String middleName = "";
String lastName = "";
String address = "";
firstName = JOptionPane.showInputDialog(null,
"Please enter your first name");
middleName = JOptionPane.showInputDialog(null,
"Please enter your middle name");
lastName = JOptionPane.showInputDialog(null,
"Please enter your last name");
address = JOptionPane.showInputDialog(null,
"Please enter your address");
firstName = firstName.toUpperCase();
middleName = middleName.toUpperCase();
lastName = lastName.toUpperCase();
JOptionPane.showMessageDialog(null, "Your ID is " +
firstName.substring(0,1) + middleName.substring(0,1) +
lastName.substring(0,1) + address.substring(0,4));
}
}
Thanks much,
Sam