Sample Session -user choosing Menu Items in no particular order.
NOTE: user input below shown in red
NOTE: the starting state had 2 entries in the AddressBook ---only to make it easier for me to have something in book --not part of design.
NOTE : (see below)as I did not stipulate what would happen when you try to add 2 of the same entires I will allow you to decide what to do ---is this a design flaw or something you need to decide as a programmer? You can allow duplicates or not --but, see discussion at the bottom of this base of a use of a datastructure for AddressBook.addressEntryList that does not allow duplicates.
e
2: D.S Malik
************************* b
e
2: Sterling Jeppson
3: D.S Malik
************************* b
e
2: Sterling Jeppson
3: D.S Malik
4: Jane Ostrich
************************* a
e
2: Maddie Felix
3: Lynne Grewe
4: Sterling Jeppson
5: D.S Malik
6: Sterling Nelson
7: Jane Ostrich
************************* c
e
2: Lynne Grewe
3: Sterling Jeppson
4: D.S Malik
5: Sterling Nelson
6: Jane Ostrich
************************* a
e
2: Maddie Felix WHY DID IT ONLY add this ONE entry & not duplicates? HINT: datastructure class used for AddressBook.addressEntrryList does not accept duplicates. What will you decide to do? SEE below for optional discussion of what solution created this no-duplicates allowed code.
3: Lynne Grewe
4: Sterling Jeppson
5: D.S Malik
6: Sterling Nelson
7: Jepsom Nelson
8: Jane Ostrich
************************* b
e
2: Maddie Felix
3: Lynne Grewe
4: Peanut Grow
5: Sterling Jeppson
6: D.S Malik
7: Sterling Nelson
8: Jepsom Nelson
9: Jane Ostrich
************************* d
2: Peanut Grow
************************* c
1: Lynne Grewe
2: Peanut Grow
2
Peanut Grow
y
f
Process finished with exit code 0 |
Discussion of No Duplicate option see above
IMPORTANT: as I did not stipulate what would happen when you try to add 2 of the same entires I will allow you to decide what to do . You can have duplicates or not --you decide.
ONE WAY TO ACHIEVE NO DPULICATES: HERE is a well thought out datastructure that allows for multiple AddressEntries with the same last name but, NOT everything in the AddressEntry can be the same, meaning no duplicates. AND it maintains the order! Yes this is a bit more complicated than a simpler datastructure that may allow duplicates.
for example: consider the use of TreeMap where the key=lastName can map to multiple entries in the TreeSet
private final TreeMap<String, TreeSet<AddressEntry>> addressEntryList = new TreeMap<>();
* Will use TreeMap where the key is a String(the last name of the AddressEntry and the value is the a TreeSet
* AddressEntry. This is because java does not contain a multiset in standard libraries.
* Tree is used instead of hash because tree preserves the natural ordering of key which makes printing in
* sorted order by last name(key) easy.
NOTE: TreeSet implements the SortedSet interface. So, duplicate values are not allowed