[Solved] Objective Make Use Java Collection Framework Implement Contact List Class Along Utility Cl Q37300151
The objective is to make use of the Java Collection framework toimplement a contact list class along with a utility class whichprovide static (some recursive) methods to support the contact listclass’s functionality. The assignment will make use ofinner classes and recursion while reinforcing skills involvingworking with generics.
Another objective is the focus on the ability to write testcases for an existing class.
Overview:
- Implement the class Contact which will be used to save basicinformation about a contact.
- Implement a utility class PhoneBookUtils which includes staticmethods to be used by the PhoneBook class when manipulating thecontact list.
- Implement the class PhoneBook, which uses a map datastructure to maintain a list of contacts, their emails and theirphone numbers.
- Implement the private inner class PhoneBookIterator whichimplements Iterable.
- Write test cases to test each method in the four classes youhave implemented
We will implement an electronic phone book. We willbuild from the ground up by making the phone book classes. We willbuild up to a tester program which populates the contact list (byreading from an input file) and implement the different methods tocheck the validity of the application. We will incorporate two moreprogramming techniques into this assignment: maps (as datastructures) and recursion.
We will use a HashMap (from the Collections Framework) to storecontact information. If we just wanted a list, we coulduse ArrayList, but by using a map data structure we can maintain amapping between a key and a value. The key would be acontact’s name, while a value entry will contain other informationrelated to the contact (email/phone). Remember that amap does not allow duplicate keys and therefore we get theguarantee that there is only one entry per contact in our datastructure. We will also implement recursive algorithmsfor sorting the list of contacts and also when searching for acontact (recursive insertion sort / binary search).
Finally, in this assignment, you are expected to write your owntest methods to test your code! We will provide you witha sample tester program which you can use for the purpose oftesting your own methods. Make sure to write enough testcases for the different scenarios for each method. Forinstance, what would happen if we try to add a duplicate contact tothe hash map? Or what would happen if we invoke the getContactListon an empty list? These border cases must be coveredwhen you are testing your code. Be sure to test yourcode thoroughly.
Rules
– Youmay import Java built-in libraries, since this is a project aboutCollections.
– Youmay add your own helper methods or data fields, but they should beprivate. You may add additional constructors which are public.
– Youmay NOT add any extra public methods other than those outlined.
– Somemethods provide specific implementation instructions, such as whichmethods must or cannot be used, or whether the method must beimplemented recursively. These constraints may be verifiedmanually.
1. Contact Task:
public class Contact implements Comparable<Contact> : Thisclass maintains information for a single contact, namely thefollowing 3 instance variables are defined: name, phone and email,all of type String. Note that this class will be usedwhen defining an entry type for the hash map used in the PhoneBookclass. Furthermore, this class implements Comparablewhich makes instances of this class to be comparable againstothers. This is useful when we need to call any of thegeneric methods in the Collection framework which requires a typethat is comparable, such as the static method Collections.sortdefined in the Collections utility class. Additionally,this class will provide the following public methods:
- A single parameterized constructor which receive 3 Stringparameters and use those values to initialize the 3 instancevariables defined by the class.
- Accessor methods (get/set) for the instance variables asfollows: getName, getEmail, getPhone, setEmail, and setPhone. Onlya get method is needed for the name field (names cannot be changedafter a contact is created), while both set and get methods areexpected for both phone and email.
- @Override public String toString() : returns a string in theformat “NAME, email: EMAIL, phone:PHONE.”. Note the dot “.” At the end of the line, forexample:
> Contact c = new Contact(“ArthurModdy”, “est@temp.com”, “703-555-5555”);
> System.out.println(c);
Arthur Moddy, email: est@temp.com,phone: 703-555-5555.
- @Override public int compareTo(Contact c) This method willreturn the result of the comparing the lowercase versions of thename portions of both contacts (a String itself is also aComparable). More precisely, the method will convert the name ofthis contact and the name of c’s contact to lowercase and invokethe compareTo() method on the former, passing in the latter as anargument to the call. It will return an integer value which is theresult of the two name strings comparison.
Testing:
a sample testing file is provided with tests for some methods,but you must write your own test cases for a majority of yourpublic methods.
Public methods behavior must adhere to the provided definitionas shown above. Be sure to test your codethoroughly. The work should be your own, not a duplicate ofsomeone else’s.
File contacts. txt:
Lance Farmersem.egestas@urnanecluctus.ca1-425-180-9073Lawrence Garciadiam@amagna.ca1-665-672-6398Petra Williamsoneuismod.in@convallisligulaDonec.co.uk1-352-344-9237Marvin Castroorci.Ut@Nuncquis.com1-340-704-1258Brielle Richardsonnisl@semNulla.com1-803-813-0239Baxter Cantuarcu.iaculis@iaculis.net1-606-427-1676Wing Mcbridevehicula.risus.Nulla@Nuncsollicitudincommodo.net1-142-956-2408Arthur Moodyest@temporerat.com1-170-451-6998Xenos Cardenasdui.in@lectus.org1-947-140-2672Madonna Pottersollicitudin@Nullamvitaediam.edu1-116-362-9565
tester is below:
/**
* On Mac/Linux:
* javac -cp .:junit-cs211.jar *.java # compile everything
* java -cp .:junit-cs211.jar E14tester # run tests
*
* On windows replace colons with semicolons: (: with 😉
* javac -cp .;junit-cs211.jar *.java # compile everything
* java -cp .;junit-cs211.jar E14tester # run tests
*/
import org.junit.*;
import static org.junit.Assert.*;
import java.util.*;
import java.io.*;
public class E14tester {
public static void main(String args[]){
org.junit.runner.JUnitCore.main(“E14tester”);
}
private int[] array1 = {3, 6, 1, 8, 7, 5, 8};
private int[][] cases1 = {
{0,0,-1}, {0,1,2}, {0,2,2}, {0,3,0}, {0,4,0}, {0,5,0},
{1,0,2}, {1,1,2}, {1,2,0}, {1,3,0}, {1,4,0}, {1,5,0},
{2,0,-1}, {2,1,0}, {2,2,0}, {2,3,0}, {2,4,0}, {2,5,0},
{3,0,0}, {3,1,0}, {3,2,0}, {3,3,0}, {3,4,0}, {3,5,0},
{4,0,-1}, {4,1,0}, {4,2,0}, {4,3,0}, {4,4,0}, {4,5,0},
{5,0,5}, {5,1,1}, {5,2,0}, {5,3,0}, {5,4,0}, {5,5,0},
{6,0,1}, {6,1,1}, {6,2,1}, {6,3,0}, {6,4,0}, {6,5,0},
{7,0,4}, {7,1,1}, {7,2,1}, {7,3,1}, {7,4,0}, {7,5,0},
{8,0,3}, {8,1,3}, {8,2,1}, {8,3,1}, {8,4,1}, {8,5,0},
{9,0,-1}, {9,1,3}, {9,2,3}, {9,3,1}, {9,4,1}, {9,5,1},
};
private int[][] sorted1 = {
// {3, 6, 1, 8, 7, 5, 8}
{1,3,5,6,7,8,8}, // 0
{1,3,5,6,7,8,8}, // 1
{3,1,5,6,7,8,8}, // 2
{3,1,5,6,7,8,8}, // 3
{3,5,6,1,7,8,8}, // 4
{5,6,3,7,8,8,1}, // 5
{6,7,5,8,8,3,1}, // 6
{7,6,8,8,5,3,1}, // 7
{8,8,7,6,5,3,1}, // 8
{8,8,7,6,5,3,1}, // 9
};
@Test(timeout=1000) public void test_findfirstdist() {
for (int[] testcase : cases1) {
int[] array = Arrays.copyOf(array1, array1.length);
int expected = testcase[2];
int actual = SortSearch.findFirstDist(array, testcase[0],testcase[1]);
String errMsg = String.format(“incorrect find first for v=%d,distance=%d”, testcase[0], testcase[1]);
assertEquals(errMsg, expected, actual);
}
}
@Test(timeout=1000) public void test_sortdist() {
for (int i = 0; i < sorted1.length; i++) {
int[] actual = Arrays.copyOf(array1, array1.length);
SortSearch.sortDist(actual, i);
int[] expected = sorted1[i];
String errMsg = String.format(“incorrect sorting result for %swith v=%d (expected=%s, actual=%s)”,
Arrays.toString(array1), i,
Arrays.toString(expected),
Arrays.toString(actual));
assertArrayEquals(errMsg, expected, actual);
}
}
@Test(timeout=1000) public void test_findkthfromv() {
for (int v = 0; v < sorted1.length; v++) {
for (int k = 1; k <= sorted1[v].length; k++) {
int[] array = Arrays.copyOf(array1, array1.length);
int actual = SortSearch.findKthFromV(array, k, v);
int expected = sorted1[v][k-1];
String errMsg = String.format(“incorrect %dth element from %d in%s”, k, v, Arrays.toString(array1));
assertEquals(errMsg, expected, actual);
}
}
}
}
Expert Answer
Answer to The objective is to make use of the Java Collection framework to implement a contact list class along with a utility cla… . . .
OR

