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.

Second, you're prompted for your middle name

Third, you're prompted for your last name

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");
                  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");
                  lastName = JOptionPane.showInputDialog(null,
                        "Please re-enter your last name");
            address = JOptionPane.showInputDialog(null,
                  "Please enter your address");
                  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));

asked 10/18/2010 10:53

Break40's gravatar image

Break40 ♦♦

1 Answers:
You may check a character, if it is an alphabet or not:

String name = "Pramod123";

if (Character.isLetter(name.charAt(5)))
      System.out.println("The fifth character is an alphabet!");
      System.out.println("The fifth character is NOT an alphabet!");
pramodkrjsr's gravatar image


Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



Asked: 10/18/2010 10:53

Seen: 329 times

Last updated: 05/25/2011 02:44