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.

Page 3 of 9 FirstFirst 12345 ... LastLast
Results 51 to 75 of 209

Thread: Address Book Program Issues

  1. #51
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    Yeah cool, so I made a driver:

    public class AddressbookDriver
    {
        public static void main(String [] args)
        {
            AddressTextUi ui = new AddressTextUi();
            ui.mainMenu();
        }
     
    }

    That links to the textUi

    import java.io.*;
    import java.util.Scanner;
     
    public class AddressTextUi
    {
    private AddressBook addressbook;
    public void mainMenu()
       {
         displayMainMenu();     
       }
    private void displayMainMenu(){
        BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in));
        AddressTextUi addressBook = new AddressTextUi();
        String act = "";
        while(true)
        {
            //displays the options
            System.out.println("\n[A] ADD ENTRY");
            System.out.println("[D] DELETE ENTRY");
            System.out.println("[U] UPDATE ENTRY");
            System.out.println("[V] VIEW ALL ENTRIES");
            System.out.println("[S] SEARCH ENTRIES BY SURNAME");
            System.out.println("[Q] Quit");
            System.out.println("Enter desired action: ");
            try{
            //gets the choice
            act = keyIn.readLine();
           }catch(Exception e){
            System.out.println("Error");
           }
           //checks for the appropriate action
           if(act.equals("A")||act.equals("a"))
           addressBook.addEntry();
           else if(act.equals("D")||act.equals("d"))
           addressBook.delEntry();
           else if(act.equals("V")||act.equals("v"))
           addressBook.viewEntries();
           else if(act.equals("U")||act.equals("u"))
           addressBook.updateEntry();
           else if(act.equals("S")||act.equals("s"))
           addressBook.searchEntry();
           else if(act.equals("Q")||act.equals("q"))
           {System.out.println("Program Closing Down");
            System.exit(0);}
           else
            System.out.println("Unknown command");
        }
     }

  2. #52
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address Book Program Issues

    if(act.equals("A")||act.equals("a"))
    The String class has a method that ignores case that you could use here.

    Now you need to add the methods to the addressbook class.

    A better design might be to do ALL the user interface in the TextUI class and use the data obtained from the user to call methods in addressbook class.

  3. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  4. #53
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    What do you mean sorry i'm really hating myself right out i need to get this finished and its pissing me off, I need it put simply as possible what needs to go exactly where or i'm going round in circles for hours and not getting anything sorted, i really appreciate the help though

  5. #54
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address Book Program Issues

    Take the required operations one at a time. Start with the add function.
    What do you need from the user to create an Address and a Name?
    When you get those, you can create a new Contact and add it to the addressbook.

  6. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  7. #55
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    Just checking is my contact class fully done

    public class Contact
    {
        private Address address;   
        private Name name;
     
     
        public Contact(Name name, Address address)  
        {  
            this.name = name;
            this.address = address;
        }     
     
        @Override  
        public boolean equals(Object obj) {  
            if (this == obj)  
                return true;  
            if (obj == null)  
                return false;  
            if (getClass() != obj.getClass())  
                return false;  
            Contact other = (Contact) obj;  
            if (address == null) {  
                if (other.address != null)  
                    return false;  
            } else if (!address.equals(other.address))  
                return false;  
     
            if (name == null) {  
                if (other.name != null)  
                    return false;  
            } else if (!name.equals(other.name))  
                return false;  
            return true;  
        }  
     
        @Override  
        public String toString() {  
            return super.toString() + "\n" + address + "\n" + name + "\n";  
        }  
    }

    I need the user to input all the values for the variables of name and address.

  8. #56
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address Book Program Issues

    As I said before:

    It looks good for now.

    It's not unusual for classes to have methods added to them as you progress into a project. In fact it is rare for me not to have to add more code and methods to a class as a project develops.

    I need the user to input all the values for the variables of name and address.
    Do that in the TextUI class. When you have the values, create the classes.

  9. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  10. #57
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    That what i have now
    ublic void addEntry(){
        BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in));
        String forename = "";
        String surname = "";
        String street = "";
        String city = "";
        String county = "";
        String country = "";
        String post = "";
        if(top == MAXENTRIES){
            System.out.println("Address Book is full");
            return;
        }
        //asks the user for the data of the address book
        try{
            System.out.print("Forename: ");
            name = keyIn.readLine();
            System.out.print("Surname: ");
            name = keyIn.readLine();
            System.out.print("Street: ");
            add = keyIn.readLine();
            System.out.print("City: ");
            add = keyIn.readLine();
            System.out.print("County: ");
            add = keyIn.readLine();
            System.out.print("Country: ");
            add = keyIn.readLine();
            System.out.print("Postcode: ");
            add = keyIn.readLine();
     
        }catch(Exception e){
            System.out.println(e);
            System.exit(0);
        }
        AddressBook  entry = new AddressBook ();
        list[top] = entry;
        top++;
     }

  11. #58
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address Book Program Issues

    What class is the addEntry method in?
    Can you describe what the method is supposed to do? Without knowing what a method is supposed to do you can NOT write its code. FIRST you define what the method is to do, THEN you write the code.

    You can NOT create a new instance of the AddressBook every time you add an entry. You should add the created new Contact to the existing AddressBook object.
    How many instances of the AddressBook class should be created in your program?

  12. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  13. #59
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    The addEntry method is in my textui, It is supposed to be asking the user to enter all the values to create a new contact that is then stored in the addressbook.
    I really havent a fucking clue i'm sorry

  14. #60
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address Book Program Issues

    1)supposed to be asking the user to enter all the values
    2)to create a new contact that is then
    3)stored in the addressbook.
    The method is to do these 3 things.
    Your code does the first.
    Now you need to do the second.
    Take the values and create the classes necessary for creating a Contact object. There are two: Name and Address
    Then create the Contact object using those 2 objects
    Then for the third item: add it to the list

  15. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  16. #61
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    Okay so at the moment
    public void addEntry(){
        BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in));
        String forename = "";
        String surname = "";
        String street = "";
        String city = "";
        String county = "";
        String country = "";
        String post = "";
        if(top == MAXENTRIES){
            System.out.println("Address Book is full");
            return;
        }
        //asks the user for the data of the address book
        try{
            System.out.print("Forename: ");
            forename = keyIn.readLine();
            System.out.print("Surname: ");
            surname = keyIn.readLine();
            System.out.print("Street: ");
            street = keyIn.readLine();
            System.out.print("City: ");
            city = keyIn.readLine();
            System.out.print("County: ");
            county = keyIn.readLine();
            System.out.print("Country: ");
            country = keyIn.readLine();
            System.out.print("Postcode: ");
            post = keyIn.readLine();
     
        }catch(Exception e){
            System.out.println(e);
            System.exit(0);
        }

    the next bit i had -
    AddressBook entry = new AddressBook ();
        list[top] = entry;
        top++;

    it expects contact which makes sense but when i change to Contact entry = new Contact();

    it can't find the constructor so i need to add something to the contact class?

  17. #62
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address Book Program Issues

    Look at your Contact class's constructor. What values does it need to create a Contact object? See post#55.
    Use those values in the call to the Contact class's constructor with the = new statement.

    Reread post#60. You need to create 2 objects that are used in the Contact class's constructor.

    Take the values and create the classes necessary for creating a Contact object. There are two: Name and Address

  18. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  19. #63
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    It's need the name and address values to create a contact object.
    So i'm creating the classes inside the textUI?
    How do i do that sorry i'm so tired and not thinking properly

  20. #64
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address Book Program Issues

    Use each of the class's constructors. You have read all the data into variables.
    Now use them in the classes constructors to create new objects.
    Something like:
    AClass aClsObj = new AClass(anArg, anotherArg, ...); // create an instance of an AClass object

  21. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  22. #65
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    So inside my textUI

    public AddressTextUi()
        {
            Name name = new Name(forename, surname);
            Address address = new Address (street, city, county, country, post);
        }

  23. #66
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address Book Program Issues

    Yes, those two statements that create new instances would use the data the addEntry method gathered.
    Then those two new instances would be used to create a new Contact object.
    And then this object would be added to the list.

  24. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  25. #67
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    I get an error message saying it expects ')' for those statements.
    So what else needs to be added to this method?
    public void addEntry()
        {
        BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in));
        String forename = "";
        String surname = "";
        String street = "";
        String city = "";
        String county = "";
        String country = "";
        String post = "";
        if(top == MAXENTRIES){
            System.out.println("Address Book is full");
            return;
        }
        //asks the user for the data of the address book
        try{
            System.out.print("Forename: ");
            forename = keyIn.readLine();
            System.out.print("Surname: ");
            surname = keyIn.readLine();
            System.out.print("Street: ");
            street = keyIn.readLine();
            System.out.print("City: ");
            city = keyIn.readLine();
            System.out.print("County: ");
            county = keyIn.readLine();
            System.out.print("Country: ");
            country = keyIn.readLine();
            System.out.print("Postcode: ");
            post = keyIn.readLine();
     
        }catch(Exception e){
            System.out.println(e);
            System.exit(0);
        }
     
        list[top] = entry;
        top++;
     
      }

  26. #68
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address Book Program Issues

    I get an error message
    If you expect a response about the error, you must post the full text of the error message.

    what else needs to be added to this method?
    What are the things that the method is supposed to do?
    Does it do all of them?

  27. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  28. #69
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    The error message is - " ')' expected"
    Well it let's the user enter the values thats it isnt it, it doesnt connect it to that entry thats there as it doesnt exist
    before i had
    AddressBook  entry = new AddressBook  ();

  29. #70
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address Book Program Issues

    Please post the full text of the error message. Something like this:
    Please copy full text of error message and paste it here. Here is a sample:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^

  30. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  31. #71
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    That is literally the error message i'm using blueJ and thats all it has to say

  32. #72
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address Book Program Issues

    Sorry, I can not see over your shoulder to know what the IDE is saying or where it is pointing.
    Where does the IDE say the problem is?
    Why don't you have the IDE add the ) or you add it?

    Otherwise, Compile the file with the problem and get an error message from the compiler.

  33. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  34. #73
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    Haha i know, for the line -
    Name name = new Name(Name forename, Name surname);

    It just says that ')' expected thats all it says there no option to add it or something. It doesnt make sense to add one either i think

  35. #74
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address Book Program Issues

    Look at your post #65 where you did it correctly and compare that with what you did in post#73

  36. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  37. #75
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    Yeah i had that initially and then got the error that the variable forename could not be found.

Page 3 of 9 FirstFirst 12345 ... LastLast

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. Issues with ascending number program
    By newtojava2011 in forum What's Wrong With My Code?
    Replies: 21
    Last Post: June 30th, 2011, 06:23 PM
  3. Address Book Help
    By clevel211 in forum Object Oriented Programming
    Replies: 4
    Last Post: November 21st, 2010, 09:42 PM
  4. How to get your computer name and IP address?
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 6
    Last Post: November 11th, 2010, 05:06 AM
  5. Array of contacts (address book)
    By smush in forum Collections and Generics
    Replies: 11
    Last Post: April 29th, 2010, 03:08 AM