Before you post any code I expect you to have compiled it and corrected any compilation errors.
If there are no errors, don't bother to post it.
Move to the next class.
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.
Before you post any code I expect you to have compiled it and corrected any compilation errors.
If there are no errors, don't bother to post it.
Move to the next class.
Gamb1t (August 25th, 2011)
Okay well so far there are no errors. I have no errors in my AddressBook class but i don't think it is complete.
public class AddressBook { //index of the last entry private int top = 0; //constant number that indicates the maximum //number of entries in the address book private static final int MAXENTRIES = 10; //array of Address Book Entries private Contact[] list; /** * Constructor for objects of class AddressBook */ public AddressBook() { list = new Contact[MAXENTRIES]; } }
For any class, you need to define what the data is it will hold and how you will manipulate that data.
What does the AddressBook class hold (its variables) and how will you manipulate that data (its methods)?
Gamb1t (August 25th, 2011)
Well the data the AddressBook holds i believe is all the data in the contact class but held as the object. I presume the methods are to set and return but i'm unsure as it just needs to hold a collection of contacts. Are the methods here meant to be the addentry and so on or are they left for the textui
On the same point in my contact class i don't have any methods just the constructor, to string and the equals so my contact class surely isn't finished
What methods do you need to add to do the set and return?AddressBook holds i believe is all the data in the contact class but held as the object. I presume the methods are to set and return but i'm unsure as it just needs to hold a collection of contacts.
Leave out the TextUI stuff.
Gamb1t (August 25th, 2011)
Classes often are not finished. You will probably have to go back and add more code as the need arises.class surely isn't finished
That's normal.
Programming is an iterative process. Do a little here, do a little there, go back, do some more here and then some there and again and again and again.
Gamb1t (August 25th, 2011)
I need to add these :
public AddressBook(Contact contact) { this.contact = contact; } public Contact getContact() { return contact; } public void setContact(Contact contact) { this.contact = contact; }
How are the Contact objects stored? How will the caller of the get method describe which Contact object he wants?
Same for the set method. What is to be set?
Gamb1t (August 25th, 2011)
I'm not sure, when you create a contact object it just ask's for you to enter name and address not any of the individual data.
With this in addressbook it will just ask you to enter something in with contact which doesn't make sense
What do your program assignment specifications say?
Gamb1t (August 25th, 2011)
Must provide the following functionality
1. Enable user to add contacts
2. User to delete existing contacts
3. User search address details based on family name
4. List all contacts in address book
Requirements:
To use these classes:
1. name class - holds the family name and others.
2. address class - holds address details as string together with postcode.
3. postcode class - holds typical british post codes of the form AA11 22BB.
4. contact class - holds name and an address.
5. addressbook class - holds collection of contacts.
6. text ui - enable user to interact.
Does reading what you posted answer your question?
Gamb1t (August 25th, 2011)
Well it just wants you hold the data so it should be fine i think
Keep going. Come back when you have an error that you don't understand.
Gamb1t (August 25th, 2011)
Okay well still being unsure of my AddressBook class.
Looking at the textui and the method addEntry it doesnt actually add to the array
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); } Name name = new Name(forename, surname); Postcode postcode = new Postcode(post); Address address = new Address(street, city, county, country); }
So i need to add this i think to the method.
AddressBook entry = new AddressBook (); list[top] = entry; top++;
It compiles fine and when i bring up the menu it works, it asks for all the inputs but i get an error when you finish the last input
"java.lang.String.NullPointerException: null" and the line of code is -list[top] = entry;
The TextUI class needs a reference to the AddressBook object that the addEntry method can use to call a method in the AddressBook class to add the entry the addEntry method has created.
Gamb1t (August 25th, 2011)
Wow statements like that make me cry haha
Sois a reference to the class but not the object.private AddressBook addressbook;
I'm got to need it breaking down a bit more its alot to take it
private AddressBook addressbook;
That defines a reference variable but does NOT give it a value.
Gamb1t (August 25th, 2011)
So i need to do use a constructor and have
public AddressTextUi(AddressBook addressbook) { this.addressbook = addressbook; }
right?
I don't know what you need. What are the program's requirements?
What class creates the AddressTextUi class?
Think about how a user will use this program.
What class will first start and then what will happen?
Gamb1t (August 25th, 2011)
The first class that kicks it off is
AddressBookDriver,
public class AddressbookDriver { public static void main(String [] args) { AddressTextUi ui = new AddressTextUi(); ui.mainMenu(); } }
This connects to the AddressTextUi class and launches the main menu that is found within the class.
The main menu displays the options to the user:
[A] ADD ENTRY
[D] DELETE ENTRY
[U] UPDATE ENTRY
[V] VIEW ALL ENTRIES
[S] SEARCH ENTRIES BY SURNAME
[Q] Quit
Enter desired action:
Like so, when the user types in Q and enters the program closes and displays a message that is fine.
When the user types A and hits enter you get this:
Enter Contact Details:
Forename:
Once the forename has been entered it asks for surname and so on.
It Also should check whether the addressbook is full if so it should display a message and go back to the main menu
Ok. Have you answered the question you asked in post#145
What happens when the user enters the other options:
D
U
V
S
Gamb1t (August 25th, 2011)
With the delete entry - it checks to see whether the addressbook is empty if so displays a message and returns to main menu.
If not then it displays all the entries of the address book with the index number, and prompts the user to enter the index number of the contact they wish to delete it then deletes and goes back to the main menu.
Update entry i dont require and am taking it out.
View entries - checks to see if its empty first, if not displays all the contacts in the address book
So far i have the view and delete entries in and i think they will work but i have this error at the end of typing in the data for the addentry method so i'm not sure and need to fix that first
Ok keep up the good work.
Gamb1t (August 25th, 2011)