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?
Printable View
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?
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.
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?
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.Quote:
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"?Quote:
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?
I just mean all the information from the name and address classes i think i'm confusing myself
Code :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.
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.Quote:
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
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
Code :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.
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.
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.
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?
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.
The main loop to be in the addressbook class?
Sorry, I meant the TextUI class sounds like a good place for the user interface
Yeah,
My addressbook class atm:
Code :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.