Your problem is that you misunderstood concept of ArrayList populated with an object type. You do not need to create array list for variable that is inside the object separately. Just create object and add it to collection.
Plus you are asked to create 5 phone book objects not ask them from user (you are complicating your own life there)
ArrayList<PhoneBookEntry> phoneBookEntries = new ArrayList<PhoneBookEntry>();
phoneBookEntry.add(new PhoneBookEntry("Peter", "0123456"));
phoneBookEntry.add(new PhoneBookEntry("Mike", "0123457"));
phoneBookEntry.add(new PhoneBookEntry("David", "0125456"));
phoneBookEntry.add(new PhoneBookEntry("Tom", "0123456"));
phoneBookEntry.add(new PhoneBookEntry("Mark", "0523456"));
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
set() and get() are for your PhoneBookENtry object add() is method of ArrayList that you need to use. There is set(int index, E element) but in your case you do not need it. Is this what you been asking about, or you had something else on your mind?
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
Your lecturer had his reasons, but for one you do need get methods so you can do for instance printing. Set method still can be used, example you create object with only one value provided. How would you set the other one?
As for the second part in regards of array list set method, no you do not use it as in array. ArrayList set method is usually used to replace existing element in the position with new one.
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902