3. postcode class - holds typical british post codes of the form AA11 22BB
Are you familiar with British postcode? I am not. In the United States, we have zip codes. They are always 5 digits, followed by a dash, followed by four digits. 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.
For your postcodes, you have to look at what the data can be. It is clearly not numeric, so you may want to hold it as a String. It looks like it is always four characters. I don't know if it's always 2 digits and 2 characters, but that may be something to validate (or it may not). also, it may be that the first two can't be digits like '33' or '97'. But basically, you need to need ways to store, set, update, and get that data.
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. You will then need the appropriate getters/setters in the Address class. Something like
This is what is called "composition". It's like legos. You take smaller pieces and hook them together to make bigger pieces. If i had a Car class, it may look like this:
Engine is an entire class to itself. It has methods, getters, and setters. I can stick one in my Car, and then call its methods.
Your contact class would have, as its members, a Address and a Name. The code for the Contact class would most likely let you pass in a Name object and an Address object.
Finally, think of a real address book. When you first buy/create it, it is empty. You can add contacts in as you need to. You can search for contacts. You can delete a contact.
Your class should probably do the same thing. Therefore, you will need some way to hold more than one. The simplest way is to make an array of Contacts, but that has a few drawbacks:
1) You have to declare how many your AddressBook will hold ahead of time
2) There is not a good way to search for a specific one, like "Fred Rosenberger"
3) There is not a good way to delete one.
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.
There is something called a Map, which lets you define a 'key' value you can use to lookup specific entries. It also grows as needed. However, it is a little more difficult to grasp as a concept than an Array. That's all.