Java Bootcamp – Workbooks and Challenges
)}

Contacts – Part 4

In this workbook, you will apply the Big 3 steps to the ContactManager class.

The contact manager is identified by the contacts that it manages. It also performs the actions of adding/removing contacts.

Task 1 – Adding the field


Add the contacts field to the ContactManager class. The number of contacts can increase or decrease, so use an ArrayList.

Task 2 – The Big 3


  1. Constructor.

    • It receives no parameters.

    • It sets the field equal to a new object of the ArrayList class.

  2. Getter: getContact

    • It receives one parameter: int index.

    • It returns an object at the requested index.

  3. Setter: setContact

    • It receives two parameters: int index, Contact contact.

    • It sets an element equal to a copy of the object being passed in.

As you're applying each step, careful not to fall into the reference trap.

Task 3 – addContact.


  • This method is void

  • Receives one parameter: Contact contact

  • Adds a contact to the ArrayList.

Task 4 – removeContact.


  • This method is void.

  • Receives one parameter: String contactName.

  • Removes the contact that matches the name passed in.

Task 5 – toString.


  • Set a String variable temp that equals "".

  • Loop through every contact in the contacts field.

  • During each run, add the toString of each contact.

  • Then , add two new lines \n\n to temp.

  • return temp;

Task 6 – Testing the code


  • Inside main(), create an object of the ContactManager class.

  • Add three contacts to the contacts field. Use the following values:

    • Ryan 6135012424 11/11/1992

    • Gio 6477092344 11/11/1993

    • Thomas 8192256979 11/11/1994

  • Print the ContactManager.

call removeContact and remove "Gio".

Good Luck!

Feedback Summary
4.8
39 students
5

92%
4

3%
3

0%
2

0%
1

5%
Written Reviews
There are no written reviews yet.