diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..62e6d1b Binary files /dev/null and b/.DS_Store differ diff --git a/AddYourNameHere.md b/AddYourNameHere.md index 7b8b00f..85c421c 100644 --- a/AddYourNameHere.md +++ b/AddYourNameHere.md @@ -4,4 +4,4 @@ Please add your first name to the list below Colin Charles Jasmin - +Zoe diff --git a/README.md b/README.md index 8d1c8b6..e9a3371 100644 --- a/README.md +++ b/README.md @@ -1 +1,7 @@ - +What functionality is working so far? + -findName, delete, insert, size, printAllContacts, searchAllContacts, and everything in Contact.java +What problems/bugs are you currently running into (if any)? + -when doing the JUnit testing for findNumber, I keep getting a fail on the assertNotNull line +Provide a planned schedule for when you aim to complete each remaining aspect of the project + -once I get help on the one error I'm getting, I'll be done and ready to turn in. + diff --git a/final_project/.DS_Store b/final_project/.DS_Store new file mode 100644 index 0000000..dc563e1 Binary files /dev/null and b/final_project/.DS_Store differ diff --git a/final_project/.classpath b/final_project/.classpath new file mode 100644 index 0000000..67995dc --- /dev/null +++ b/final_project/.classpath @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/final_project/.gitignore b/final_project/.gitignore new file mode 100644 index 0000000..cb49881 --- /dev/null +++ b/final_project/.gitignore @@ -0,0 +1,3 @@ +/ContactListTest.class +/ContactTest.class +/bin/ diff --git a/final_project/.project b/final_project/.project new file mode 100644 index 0000000..15aa50e --- /dev/null +++ b/final_project/.project @@ -0,0 +1,17 @@ + + + final_project + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/final_project/.settings/org.eclipse.jdt.core.prefs b/final_project/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..910a770 --- /dev/null +++ b/final_project/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=14 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=14 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=14 diff --git a/final_project/src/Contact.class b/final_project/src/Contact.class new file mode 100644 index 0000000..9a9b47e Binary files /dev/null and b/final_project/src/Contact.class differ diff --git a/final_project/src/Contact.java b/final_project/src/Contact.java new file mode 100644 index 0000000..7f70194 --- /dev/null +++ b/final_project/src/Contact.java @@ -0,0 +1,36 @@ +import java.util.HashMap; + +public class Contact { + String myName; + String myNumber; + HashMap contact = new HashMap<>(); + + public Contact(String name, String number) { + myName = name; + myNumber = number; + }// 2 parameter constructor + + public Contact() { + this(null, null); + }// 0 parameter constuctor + + public String getName() { + return myName; + }//getName + + public void setName(String name) { + myName = name; + }//setName + + public String getNumber() { + return myNumber; + }//getNumber + + public void setNumber(String number) { + myNumber = number; + }//setNumber + + public String toString() { + return myNumber; + } +}//Contact \ No newline at end of file diff --git a/final_project/src/ContactList$Main.class b/final_project/src/ContactList$Main.class new file mode 100644 index 0000000..a6c334f Binary files /dev/null and b/final_project/src/ContactList$Main.class differ diff --git a/final_project/src/ContactList.class b/final_project/src/ContactList.class new file mode 100644 index 0000000..8fb25ac Binary files /dev/null and b/final_project/src/ContactList.class differ diff --git a/final_project/src/ContactList.java b/final_project/src/ContactList.java new file mode 100644 index 0000000..569ce27 --- /dev/null +++ b/final_project/src/ContactList.java @@ -0,0 +1,161 @@ +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; + +public class ContactList { + Map theList = new HashMap<>(); + Map theNums = new HashMap<>(); + private int size; + + //constructor + public ContactList() { + //contact = new HashMap(); + size = 0; + theList = new HashMap(); + theNums = new HashMap(); + } + + /* + * Running time: O(1) + * Analysis: returns true once the new person is inserted into theList + */ + public boolean insert(String name, String number) { + if((theList.containsKey(name) || theList.containsKey(number)) + || (theNums.containsKey(number) || theNums.containsKey(number))) { + System.out.print("Duplicate detected.\n"); + return false; + } + if(name == null && number == null) { + System.out.print("No name or number given."); + return false; + } + Contact info = new Contact(name, number); + theList.put(name, info); + theNums.put(number, info); + return true; + }//insert + + /* + * Running time: O(1) + * Analysis: returns the name of the person searched if found, if not found, return null; + */ + public Contact findName(String name) { + if(theList.containsKey(name)) { + //System.out.print("Found: " + name + "\n"); + return theList.get(name); + }//if + //System.out.print("No name found\n"); + return null; + }//findName + + /* + * Running time: O(1) + * Analysis: returns the number of the person searched if found, if not found, return null; + */ + public Contact findNumber(String number) { + if(theNums.containsKey(number)) { + return theNums.get(number); + }//if + return null; + }//find + + /* + * Running time: O(1) + * Analysis: deletes the person with the nameOrNumber passed through; + */ + public void delete(String nameORnumber) { + if(theList.containsKey(nameORnumber)) { + theList.remove(nameORnumber); + //System.out.print(nameORnumber + " has been removed\n"); + + } else if (theNums.containsKey(nameORnumber)) { + theNums.containsKey(nameORnumber); + } else { + System.out.print(nameORnumber + " is not in the hashmap\n"); + }//else + }//delete + + /* + * Running time: O(1) + * Analysis: returns the size of the theList; + */ + public int size() { + return theList.size(); + }//size + + /* + * Running time: O(n log n) + * Analysis: returns the names of everyone in the list, sorted by name; + */ + public void printAllContacts() { + TreeMap temp = new TreeMap<>(theList); + System.out.println("unsorted:" + theList); + + System.out.println("sorted: "); + + for(Map.Entry entry : temp.entrySet()) { + System.out.println( entry.getKey() + " " + entry.getValue()); + } + }//printALLContacts + + /* + * Running time: O(n log n) + * Analysis: returns the name and number of the person passed through in the parameter; + */ + public void searchAllContacts(String target) { + //is target string in the key + for(Map.Entry entry : theList.entrySet()) { + if(entry.getKey().contains(target)){ + System.out.println(entry.getKey() + " " + entry.getValue()); + } + }//for + }//searchALLContacts + + // https://www.baeldung.com/java-check-string-number + private static boolean isNumeric(String strNum) { + try { + long l = Long.parseLong(strNum); + } catch (NumberFormatException | NullPointerException nfe) { + return false; + } + return true; + } + + public static class Main { + public static void main(String[] args) { + ContactList person = new ContactList(); + + System.out.print("testing insert & printAllContacts: \n"); + person.insert("sophee mae", "123-000-8888"); + person.insert("sophee smith", "209-209-8388"); + + person.insert("kelly", "123-111-2234"); + person.insert("ally", "333-200-2957"); + person.insert("bob", "444-161-3574"); + person.printAllContacts(); + + + System.out.print("\ntesting searchAllContacts: \n"); + person.searchAllContacts("ob"); + } + } +}//HashMap + + + + + + + + + + + + + + + + + + diff --git a/final_project/test/ContactListTest.class b/final_project/test/ContactListTest.class new file mode 100644 index 0000000..76b8615 Binary files /dev/null and b/final_project/test/ContactListTest.class differ diff --git a/final_project/test/ContactListTest.java b/final_project/test/ContactListTest.java new file mode 100644 index 0000000..90d1e79 --- /dev/null +++ b/final_project/test/ContactListTest.java @@ -0,0 +1,59 @@ +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.After; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + + +public class ContactListTest { + private ContactList contactListTest = new ContactList(); + @Before + public void setUp() throws Exception { + contactListTest = new ContactList(); + contactListTest.insert("sally", "123-456-7890"); + contactListTest.insert("sharol", "123-456-7891"); + contactListTest.insert("diane", "530-456-1592"); + contactListTest.insert("conny", "028-263-0011"); + + } + @Test + public void testFindName () { + Contact person = contactListTest.findName("sally"); + assertNotNull(person); + assertEquals("sally", person.getName()); + assertNull(contactListTest.findName("fred")); + } + @Test + public void testFindNumber () { + Contact person = contactListTest.findNumber("123-456-7890"); + assertNotNull(person); + assertEquals("sally", person.getName()); + assertEquals("123-456-7890", person.getNumber()); + assertNull(contactListTest.findNumber("123-111-1133")); + } + + @Test + public void testDelete () { + contactListTest.delete("sharol"); + assertNull(contactListTest.findName("sharol")); + } + + @Test + public void testInsert () { + boolean insertPerson = contactListTest.insert("random", "000-999-2233"); + assertTrue(insertPerson); + insertPerson = contactListTest.insert("sally", "123-456-7890"); + assertFalse(insertPerson); + } + + @Test + public void testOthers () { + assertEquals(contactListTest.size(), contactListTest.size()); + System.out.println("searchAllContacts:"); + contactListTest.searchAllContacts("sally"); + contactListTest.printAllContacts(); + + } + + // other tests to be included +} diff --git a/final_project/test/ContactTest.class b/final_project/test/ContactTest.class new file mode 100644 index 0000000..bd4d092 Binary files /dev/null and b/final_project/test/ContactTest.class differ diff --git a/final_project/test/ContactTest.java b/final_project/test/ContactTest.java new file mode 100644 index 0000000..9f6b5be --- /dev/null +++ b/final_project/test/ContactTest.java @@ -0,0 +1,31 @@ +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; + +public class ContactTest { + + @Test + public void testGetters () { + Contact person1 = new Contact("harold", "209-555-9988"); + assertEquals("harold", person1.getName()); + assertEquals("209-555-9988", person1.getNumber()); + + } + + @Test + public void testSetters () { + Contact person1 = new Contact("harold", "209-555-9988"); + person1.setName("mary"); + assertEquals("mary", person1.getName()); + person1.setNumber("209-555-9989"); + assertEquals("209-555-9989", person1.getNumber()); + + } + + @Test + public void testString () { + Contact person1 = new Contact("harold", "209-555-9988"); + assertEquals("harold, 209-555-9988", person1.toString()); + } +} \ No newline at end of file