Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3975648
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:42:36+00:00 2026-05-20T04:42:36+00:00

hope you can help me coding. What i need to do: 1.) I should

  • 0

hope you can help me coding.

What i need to do:
1.) I should not allow user to have a blank entry.. I should prompt them like “No name inputted!”
2.) I should not allow user to input same entry..

I have no Idea how to code i, please help.

Here’s my complete code:

public class AddressBook {

private AddressBookEntry entry[];
private int counter;
private String SName;
private int notfound=0;

public static void main(String[] args) {
    AddressBook a = new AddressBook();
    a.entry = new AddressBookEntry[100];
    int option = 0;
    while (option != 5) {
        String content = "Choose an Option\n\n"
                + "[1] Add an Entry\n"
                + "[2] Delete an Entry\n"
                + "[3] Update an Entry\n"
                + "[4] View all Entries\n"
                + "[5] View Specific Entry\n"
                + "[6] Exit";
        option = Integer.parseInt(JOptionPane.showInputDialog(content));
        switch (option) {
            case 1:
                a.addEntry();
                break;
            case 2:
                a.deleteEntry();
                break;
            case 3:
                a.editEntry();
                break;
            case 4:
                a.viewAll();
                break;
            case 5:
                a.searchEntry();
                break;
            case 6:
                System.exit(1);
                break;
            default:
                JOptionPane.showMessageDialog(null, "Invalid Choice!");
        }
    }
}

public void addEntry() {
    entry[counter] = new AddressBookEntry();
    entry[counter].setName(JOptionPane.showInputDialog("Enter name: "));
    entry[counter].setAdd(JOptionPane.showInputDialog("Enter add: "));
    entry[counter].setPhoneNo(JOptionPane.showInputDialog("Enter Phone No.: "));
    entry[counter].setEmail(JOptionPane.showInputDialog("Enter E-mail: "));
    counter++;
}

public void viewAll() {
    String addText = "  NAME\tADDRESS\tPHONE NO.\tE-MAIL ADD\n\n";
    int nonNull = 0;
    for (int i = 0; i < entry.length; i++) {
        if (entry[i] != null) {
            addText = addText + entry[i].getInfo() + "\n";
            nonNull++;
        }
        if (nonNull == counter) {
            break;
        }
    }
    JOptionPane.showMessageDialog(null, new JTextArea(addText));
}

public void searchEntry() {
    SName = JOptionPane.showInputDialog("Enter Name to find: ");
    searchMethod();
}

public void searchMethod() {
    for (int i = 0; i < counter; i++) {
        if (entry[i].getName().equals(SName)) {
            JOptionPane.showMessageDialog(null, entry[i].getInfo2());
            notfound = 0;
            break;
        } else {
            notfound++;
        }
    }
    if (notfound != 0) {
        JOptionPane.showMessageDialog(null, "Name Not Found!");
    }
}
public void editEntry() {
    int notfound = 0;
    SName = JOptionPane.showInputDialog("Enter Name to edit: ");
    for (int i = 0; i < counter; i++) {
        if (entry[i].getName().equals(SName)) {
            entry[i] = new AddressBookEntry();
            entry[i].setName(JOptionPane.showInputDialog("Enter new name: "));
            entry[i].setAdd(JOptionPane.showInputDialog("Enter new add: "));
            entry[i].setPhoneNo(JOptionPane.showInputDialog("Enter new Phone No.: "));
            entry[i].setEmail(JOptionPane.showInputDialog("Enter new E-mail: "));
            notfound = 0;
            break;
        } else {
            notfound++;
        }
    }
    if (notfound != 0) {
        JOptionPane.showMessageDialog(null, "Name Not Found!");
    }
}
public void deleteEntry() {
    SName = JOptionPane.showInputDialog("Enter Name to delete: ");
    for (int i = 0; i < counter; i++) {
        if (entry[i].getName().equals(SName)) {
            JOptionPane.showMessageDialog(null, "Found!");
            entry[i] = null;
            break;
        }
    }
}

}

What happen to my code was it allows user to click “OK” even he doesn’t enter any character yet.. and it also allows identical entry…

Hope you can help me… i need it very soon and yet i still have no Idea what to add in my code… please help thanks a lot..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:42:37+00:00Added an answer on May 20, 2026 at 4:42 am

    What happen to my code was it allows user to click “OK” even he doesn’t enter any character yet.. and it also allows identical entry…

    The showInputDialog method lets the user input any string he wants, or also nothing. If you don’t want this, you can either use a self-made dialog, patch the JOptionPane (using a subclass or such), or simply show the dialog again when it is not one of your given strings, like this:

    String input = JOptionPane.showInputDialog(content);
    try {
       option = Integer.parseInt(input);
    }
    catch(NumberFormatException ex) {
       // the user typed nothing, or something that is not an integer
       // TODO: show error message
       // => go to next iteration of while loop.
       continue; 
    }
    // and now our switch ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question really has three related parts which I hope you can help me
I hope there's a SharePoint expert here on SO who can help with this.
I hope someone can guide me as I'm stuck... I need to write an
I hope I can explain this clearly enough. I have my main form (A)
hope you can help. I am recording audio from a microphone and streaming it
I hope there is someone who can help me with this regex content.match(/<div class=content>.+#-#/ig);
hope you can help me with this one… I saw some crazy behavior so
hope you can help me (tried lots of things here, but nothing worked) i
Hope anyone can shed light on this so I can use pens with dash
this is my first question here so I hope I can articulate it well

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.