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 6887799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:55:44+00:00 2026-05-27T05:55:44+00:00

I’m just doing a small program. It’s an address book which has four options:

  • 0

I’m just doing a small program. It’s an address book which has four options:

  1. insert new contact
  2. search contact by last name
  3. delete contact by name
  4. show all contacts
  5. exit program

Just wondering how to get the insert contact part and how to store it. I’ve hardcoded one contact to test it.

Here is my code I have started

package addressbook;
import java.util.Scanner;

public class addressbooks
{


    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);

        //create a table to hold information

        String[][] addressbooks = new String[100][8];

        addressbooks[0][0]="Mobile Number";
        addressbooks[0][1]="First Name";
        addressbooks[0][2]="Last Name";
        addressbooks[0][3]="Address";
        addressbooks[0][4]="City";
        addressbooks[0][5]="County";
        addressbooks[0][7]="Telephone Number";

        //pre-populate address book for testing purposes and records

        addressbooks[1][0]="1";
        addressbooks[1][1]="David";
        addressbooks[1][2]="Needham";
        addressbooks[1][3]="Sraheens, Achill";
        addressbooks[1][4]="Galway";
        addressbooks[1][5]="Mayo";
        addressbooks[1][6]="086-1581077";
        addressbooks[1][7]="098-45368";

        addressbooks[2][0]="2";
        addressbooks[2][1]="Mc";
        addressbooks[2][2]="lovin";
        addressbooks[2][3]="Hawaii";
        addressbooks[2][4]="Hawaii";
        addressbooks[2][5]="Hawaii";
        addressbooks[2][6]="12345";
        addressbooks[2][7]="412-555-1234";

        //menu options
        System.out.print("Welcome to my Address book!");
        System.out.print("\n");
        System.out.print("\n1 - Insert a New Contact \n2 - Search Contact by Last Name \n3 - Delete Contact \n4 - Show All Contacts \n5 - Exit " );
        System.out.print("\n");
        System.out.print("\nChoose your option: ");

        int option = input.nextInt();

        if (option ==1)
        {
            System.out.print("\nPlease enter your First Name : ");
        }
        if (option ==2)
        {
        }

        if (option ==3)
        {
        }

        if (option ==4)
        {
        System.out.println(addressbooks[1][0]+
        "\t"+addressbooks[1][2]+ ", "+addressbooks[1][1]+
        "\n\t"+addressbooks[1][3]+
        "\n\t"+addressbooks[1][4]+ ", "+addressbooks[1][5]+ " "+addressbooks[1][6]+
        "\n\t"+addressbooks[1][7]);
        }

        if (option ==5)
        {
        }

    }
}
  • 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-27T05:55:44+00:00Added an answer on May 27, 2026 at 5:55 am

    I’d start like this:

    package model;
    
    public class Person {
        private String firstName;
        private String lastName;
        // What else means something to your problem?  Birthday?
        // Constructors, getters (make them immutable), equals/hashCode
    }
    
    public class Address {
        private String street;
        private String city;
        private String county;
        private String postalCode;
        // Constructors, getters (make them immutable), equals/hashCode
    }
    
    public class AddressBook {
        private Map<Person, Address> contacts = new ConcurrentHashMap<Person, Address>();
    
        public void addContact(Person p, Address a) {
            this.contacts.put(p, a);
        }
    
        public void removeContact(Person p) {
            this.contacts.remove(p);
        }
    
        public Collection<Person> findAllContacts() {
            return new Collections.unmodifiableCollection(this.contacts.keySet());
        }
    
        public boolean hasContact(Person p) {
            return this.contacts.contains(p);
        }
        // etc.
    }
    

    I would recommend separating all that stuff about text-based IO out away from the fundamentals of your problem. If you get it right, the next step is to write a web UI. Most of the code will be reusable if you do it correctly.

    Think about layering your app:

    view->services->persistence
    

    Model classes might be used in all three layers.

    The answer recommending JDBC isn’t wrong. If you write your service and persistence classes as interfaces, you’ll find it easy to swap out an in-memory Map of Contacts for a database version that uses JDBC:

    package persistence;
    
    public interface ContactDao {
        Collection<Contact> find();
        Contact find(Long id);
        Collection<Contact> find(String lastName);
        Collection<Contact> find(Address address);
        Long save(Contact c);
        void update(Contact c);
        void delete(Contact c);
    }
    

    There are lots of ways to do things. I’ve already changed my mind: I’ve introduced a Contact class:

    package model; 
    
    public class Contact {
        private Person;
        private Address;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.