Skip to content
This repository was archived by the owner on Jan 17, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion AddYourNameHere.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Please add your first name to the list below
Colin
Charles
Jasmin

Zoe
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Binary file added final_project/.DS_Store
Binary file not shown.
12 changes: 12 additions & 0 deletions final_project/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-14">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
3 changes: 3 additions & 0 deletions final_project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/ContactListTest.class
/ContactTest.class
/bin/
17 changes: 17 additions & 0 deletions final_project/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>final_project</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
14 changes: 14 additions & 0 deletions final_project/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -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
Binary file added final_project/src/Contact.class
Binary file not shown.
36 changes: 36 additions & 0 deletions final_project/src/Contact.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.util.HashMap;

public class Contact {
String myName;
String myNumber;
HashMap<String, String> 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
Binary file added final_project/src/ContactList$Main.class
Binary file not shown.
Binary file added final_project/src/ContactList.class
Binary file not shown.
161 changes: 161 additions & 0 deletions final_project/src/ContactList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class ContactList {
Map<String, Contact> theList = new HashMap<>();
Map<String, Contact> theNums = new HashMap<>();
private int size;

//constructor
public ContactList() {
//contact = new HashMap<String, String>();
size = 0;
theList = new HashMap<String, Contact>();
theNums = new HashMap<String, Contact>();
}

/*
* 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<String, Contact> temp = new TreeMap<>(theList);
System.out.println("unsorted:" + theList);

System.out.println("sorted: ");

for(Map.Entry<String, Contact> 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<String, Contact> 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


















Binary file added final_project/test/ContactListTest.class
Binary file not shown.
59 changes: 59 additions & 0 deletions final_project/test/ContactListTest.java
Original file line number Diff line number Diff line change
@@ -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
}
Binary file added final_project/test/ContactTest.class
Binary file not shown.
31 changes: 31 additions & 0 deletions final_project/test/ContactTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}