Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Address Book Program in java

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Address Book Program in java

    Hi im looking for help doing a small program, an addressbook that allows the user option to:

    add contact, search contact and delete contact menu

    all of this data is read and written to .dat file.

    Also how would you create a layout in the data file, ie name,lastname,address and number?

    my code:

    public interface Inter
    {
    //Interface class
     
     
        public void addContact();
        public void deleteContact();
        public void searchContact();
        public void readFile();
    }
     
    public class Contact
    {
     
        static String name;
        static String lastName;
        static String address;
        static String number;
     
     
     
     
        public Contact ()
        {
     
     
        }
     
     
    }
     
     
     
     
    public class Phonebook extends Contact implements Inter
        {
     
     
            public static void main(String[] args)
            {
     
     
            } // main
     
     
     
            @Override
            public void deleteContact()
            {
     
     
            }
     
            @Override
            public void searchContact()
            {
     
     
            }
     
     
     
            @Override
            public void addContact()
            {
     
                String details = null;
                System.out.println("Enter new contact i.e name:number:lastname ");
                InputStreamReader converter = new InputStreamReader(System.in);
                BufferedReader in = new BufferedReader(converter);
     
                try
                {
                    details=in.readLine();
                    String[] tokens =details.split(":"); // eg david :098:Needham
                    name= tokens[0];
                    lastName = tokens[1];
                    address = tokens[2];
                    number = tokens[3];
     
     
     
     
     
     
     
                }
     
                catch (IOException e1)
                {
     
                }
     
     
     
     
     
                    FileWriter fw = null; // writes contact info to the dat file
                    try
                    {
                        fw = new FileWriter("data.dat");
                        fw.write(name);
                        fw.write(lastName);
                        fw.write(address);
                        fw.write(number);
     
                    } catch (IOException e) {
     
                    }
                    BufferedWriter bw = new BufferedWriter(fw);
     
     
     
            }
     
     
     
     
     
     
            public void readFile() // reads contacts from dat file
            {
     
                try
                {
                    BufferedReader in = new BufferedReader(new FileReader("data.dat"));
                     String str;
                        while ((str = in.readLine()) != null)
                        {
     
     
                        }
     
                 }
     
     
                catch(Exception ex){}
     
     
     
            }
        }

    Help is much apperciated!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Address Book Program in java

    Please post your questions or the text of the error messages you need help with.

    how would you create a layout in the data file
    You could put all those fields (name address etc) in one String separating each field with a ;
    and write that String out to the file with a lineend character to separate one line from another

Similar Threads

  1. Source code for Email address book/contacts importer
    By jega004 in forum Java Theory & Questions
    Replies: 4
    Last Post: November 23rd, 2012, 12:49 PM
  2. Java Error cannot be applied to (java.lang.String), phone book entry program.
    By iceyferrara in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 23rd, 2011, 06:32 AM
  3. Address Book Program Issues
    By Gamb1t in forum What's Wrong With My Code?
    Replies: 208
    Last Post: August 25th, 2011, 08:43 PM
  4. Address Book Help
    By clevel211 in forum Object Oriented Programming
    Replies: 4
    Last Post: November 21st, 2010, 09:42 PM
  5. Array of contacts (address book)
    By smush in forum Collections and Generics
    Replies: 11
    Last Post: April 29th, 2010, 03:08 AM

Tags for this Thread