Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

How to change a Java Programming construct?

Avatar of Break40
Break40 asked on
JavaEditors IDEs
1 Comment1 Solution533 ViewsLast Modified:
I have a ConstructID that is part of a program that constructs an ID using name and address, but what if someone's address begins with a letter instead of the numbers? My address starts W7935, which would make my ID SWLW793 instead of the SWL7935.

Is there a way to program it for the different addresses that start with a letter and for some addresses that dont start with a letter?

The output looks like this:

First, you're prompted for your first name.
George

Second, you're prompted for your middle name
Albert

Third, you're prompted for your last name
Lopez

Fourth, you're prompted for your street address.
123 Main Street

Lastly, the id of GAL 123 is assigned.

How do I get a letter to show up for an address
where the number is?

Then, an id is assigned.

Here is the 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");
            while(firstName.equals(""))
                  {
                  firstName = JOptionPane.showInputDialog(null,
                        "Please re-enter your first name");
                  }      
            middleName = JOptionPane.showInputDialog(null,
                  "Please enter your middle name");
            lastName = JOptionPane.showInputDialog(null,
                  "Please enter your last name");
                        while(lastName.equals(""))
                  {
                  lastName = JOptionPane.showInputDialog(null,
                        "Please re-enter your last name");
                  }
            address = JOptionPane.showInputDialog(null,
                  "Please enter your address");
                        while(address.equals(""))
                  {
                  address = JOptionPane.showInputDialog(null,
                        "Please re-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));
            
      }
}
ASKER CERTIFIED SOLUTION
Avatar of Pramod Kumar
Pramod KumarFlag of India image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answers