There is something called a Map, which lets you define a 'key' value you can use to lookup specific entries. You can use an ArrayList, which will grow automatically if it needs to, which solves #1, but you still have problems with #2 and #3. The simplest way is to make an array of Contacts, but that has a few drawbacks:ġ) You have to declare how many your AddressBook will hold ahead of timeĢ) There is not a good way to search for a specific one, like "Fred Rosenberger"ģ) There is not a good way to delete one. Therefore, you will need some way to hold more than one. Your class should probably do the same thing. When you first buy/create it, it is empty. The code for the Contact class would most likely let you pass in a Name object and an Address object.įinally, think of a real address book. Your contact class would have, as its members, a Address and a Name. I can stick one in my Car, and then call its methods. If i had a Car class, it may look like this:Įngine is an entire class to itself. You take smaller pieces and hook them together to make bigger pieces. You will then need the appropriate getters/setters in the Address class. Once you ahve the Postcode class written, you just put one in your Address class in the same way you'd put in a String to hold something. But basically, you need to need ways to store, set, update, and get that data. also, it may be that the first two can't be digits like '33' or '97'. I don't know if it's always 2 digits and 2 characters, but that may be something to validate (or it may not). It looks like it is always four characters. It is clearly not numeric, so you may want to hold it as a String. So, if I were creating a Zipcode class, I would need a way to store the data and validate it - just like i do with any other piece of data.įor your postcodes, you have to look at what the data can be. They are always 5 digits, followed by a dash, followed by four digits. However i am a bit confused about what is required by the postcode class and i'm struggling to work out how to link the name and address classes into a contact class and then the addressbook class which will then link to the text ui.Īlso do i keep it as an array list or do i need to create and store the data added into a fileĪny help and guidance would be appreciated thanksĪre you familiar with British postcode? I am not. I need to split this single class up into these several classes and link them, I have created the name class and the address class. To begin with i created a single class that held the name and address in an arraylist and linked it to a text ui class to get all the functionality working. addressbook class - holds collection of contacts contact class - holds name and an addressĥ. postcode class - holds typical british post codes of the form AA11 22BBĤ. address class - holds address details as string together with postcodeģ. name class - holds the family name and others.Ģ. Problem: Create an addressbook that allows user to add, delete, search contacts by family name and list all contacts.ġ.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |