Your constructor call (= new...) is not correct. You don't specify the datatype in the call, only the variable name.
Why do you have the change and set methods? What do you need to do after the constructor creates the new Contact object?
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.
Your constructor call (= new...) is not correct. You don't specify the datatype in the call, only the variable name.
Why do you have the change and set methods? What do you need to do after the constructor creates the new Contact object?
Last edited by Norm; August 24th, 2011 at 10:57 AM.
Gamb1t (August 25th, 2011)
Ahh i see, erm i need to invoke the methods from the other 2 classes?
What methods? For what reason? From what classes?
I have no idea what you are trying to do.
I would think a copy method would create and return a new object with the contents of the current object.
Gamb1t (August 25th, 2011)
I need to have a method createContact i presume that then lets you enter all the variables for the name and for the address and hold it.
Then the addressbook class will hold a collection of these contacts in an array.
So i should scrap the copy method. I have a copy within my address class too
What methods you write depends on the project's requirements.
What class is the createContact method in? Does it return a Contact object?
Where does it get the data it needs to create the Contact object?
Gamb1t (August 25th, 2011)
Well my project's requirements is to hold a name and an address in the contact class.
Address Book class holds a collection of contacts.
My thought is createContact method would be in the contact class, it would get the data from the user uses the variables setup by the other classes and hold all that information
That makes sense. The code to get the data to build an object could be in the object itself.createContact method would be in the contact class, it would get the data from the user
I have no idea what the rest of your statement means.
What other classes and what "all that information"?uses the variables setup by the other classes and hold all that information
The contact class holds references to two objects. Is there more to it than that?
Could those two classes have create methods that get the user input needed to create and return an object?
Gamb1t (August 25th, 2011)
I just mean all the information from the name and address classes i think i'm confusing myself
public void createContact(Name forename, Name surname, Address street, Address city, Address county, Address country, Postcode post) { this.forename = forename; this.surname = surname; this.street = street; this.city = city; this.county = county; this.country = country; this.post = post; }
Though it can't seem to find the variable forename
What is the createContact method supposed to do? Does it return any value?
What class is it to be in?
Until you answer those questions, you can NOT write the code for the method.
Gamb1t (August 25th, 2011)
Well my contact class askes to hold a name and address so i think i need to have this method so it asks for the users input and holds it all.
I'm getting really confused i only have the rest of day and tomorrow to finish this program and getting really frustrated
Yes the Contact holds a Name object and an Address object.contact class askes to hold a name and address
You still have not answered this question:
What is the createContact method supposed to do? Does it return any value?
What class is it to be in?
Why do you need a createContact method?
You can create a Contact class object by using its constructor:
Name aName = ... (somehow get a Name object)
Address anAddr = ... (somehow get an Address object)
Contact aContact = new Contact(aName, anAddr); // create an instance of the Contact class
Gamb1t (August 25th, 2011)
Yeah i realised now the createContact method needs to be in my addressBook class,
So this covers all of that then?
So i know you must be getting really frustrated and have probably repeated yourself so many times.
Really appreciate you trying to help
public class Contact { private Address address; private Name name; public Contact(Name name, Address address) { this.name = name; this.address = address; }
That looks like what you had back at post#23
It should be a start on defining the class.
Gamb1t (August 25th, 2011)
So do i add
Name aName = ... (somehow get a Name object)
Address anAddr = ... (somehow get an Address object)
Contact aContact = new Contact(aName, anAddr); // create an instance of the Contact class
into the constructor or i need the Name aName instead of the this.name that i currently have.
That code I posted is only a sample for the syntax. The names I chose are arbitrary.
Your code looks OK for a constructor to build a new object given the two objects to be added.
Gamb1t (August 25th, 2011)
so is my contact class fine and done or do i need something else. Sorry i really would like to get this done. I just need explicitly telling exactly what i need for each class
It looks good for now. Look at the assignment requirements. What do they say?
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.
Gamb1t (August 25th, 2011)
All my requirements say are what the classes should do:
So contact class - holds a name and an address
Address book class which holds a collection of contacts
Text based user interface to enable user to interact with the address book
The addressbook needs to, enable a user to add new contacts,delete contacts, search by last name and list all contacts
Is the Addressbook class the main class with a loop that displays the "menu" that asks the user what he wants to do?
Gamb1t (August 25th, 2011)
I had it so the textUI would display the menu and the options and then they would be the methods that are in the Addressbook class
Ok, that sounds like a good place for the main loop.
Gamb1t (August 25th, 2011)
The main loop to be in the addressbook class?
Sorry, I meant the TextUI class sounds like a good place for the user interface
Gamb1t (August 25th, 2011)
Yeah,
My addressbook class atm:
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]; } }
And do i want all the methods for add entry so on in this class?
You said:
The addressbook needs to, enable a user to add new contacts,delete contacts, search by last name and list all contacts
Then the addressbook class will need methods to do all that.
Gamb1t (August 25th, 2011)