From ea32a0cecb811b02b3c92e51244d62ad259b798c Mon Sep 17 00:00:00 2001 From: zoe Date: Wed, 21 Oct 2020 09:34:36 -0700 Subject: [PATCH 1/5] adding name to .md --- AddYourNameHere.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From eaecc2674ee0ea4a0367d93599d6daa7d5731da6 Mon Sep 17 00:00:00 2001 From: zoe Date: Fri, 4 Dec 2020 17:04:04 -0800 Subject: [PATCH 2/5] commit - first commit, done w/ contactTest, contact class --- final_project/.DS_Store | Bin 0 -> 6148 bytes final_project/.classpath | 11 ++ final_project/.gitignore | 2 + final_project/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 14 ++ final_project/ContactListTest.java | 52 +++++++ final_project/ContactTest.java | 32 +++++ final_project/final_project/.gitignore | 3 + final_project/final_project/Contact.java | 38 +++++ final_project/final_project/ContactList.java | 135 ++++++++++++++++++ 10 files changed, 304 insertions(+) create mode 100644 final_project/.DS_Store create mode 100644 final_project/.classpath create mode 100644 final_project/.gitignore create mode 100644 final_project/.project create mode 100644 final_project/.settings/org.eclipse.jdt.core.prefs create mode 100644 final_project/ContactListTest.java create mode 100644 final_project/ContactTest.java create mode 100644 final_project/final_project/.gitignore create mode 100644 final_project/final_project/Contact.java create mode 100644 final_project/final_project/ContactList.java diff --git a/final_project/.DS_Store b/final_project/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a53741b4815096db1822daadfb69d1f8673819d0 GIT binary patch literal 6148 zcmeHK%}T>S5T3PB6GiMn(Bodb^^i(YFG8q#@Fqm`pwcEbY9wY$lUlS^@*4U^K7p^} z%Nvs4A9wKf=h@Yg#bRD-v}-s4|`cVOhkxYuVFihv)pyx*i6Zqotw8E z$99&SbN^cO{5;6JSv}~SQtvRxuS0Dg36YHKAUuwvUZcFSE7ClO)2JhZ<5q+&XD4ym z61}?Urmak_9R7+3{*XU_16ygjDQ=y0|l<5+Ksc;HXjTzWyH%GCjk9VPL8lVAh_$ zSI3m}+d7dPy|o;*iAq9#g+dvEjed@$K~M1-suY~#WFUGP3xzm>Vm< + + + + + + + + + + diff --git a/final_project/.gitignore b/final_project/.gitignore new file mode 100644 index 0000000..6f16c47 --- /dev/null +++ b/final_project/.gitignore @@ -0,0 +1,2 @@ +/ContactListTest.class +/ContactTest.class 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/ContactListTest.java b/final_project/ContactListTest.java new file mode 100644 index 0000000..3105c83 --- /dev/null +++ b/final_project/ContactListTest.java @@ -0,0 +1,52 @@ +import final_project.Contact; +import final_project.ContactList; +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.After; +import org.junit.Test; + +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"); + } + @Test + public void testFindName () { + Contact person = contactListTest.findName("sally"); + assertNotNull(person); + assertEquals("sally", person.getName()); + assertNull(contactListTest.findNumber("123-456-7891")); + } +// @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 testSize () { + assertEquals(contactListTest.size(), contactListTest.size()); + } + + // other tests to be included +} diff --git a/final_project/ContactTest.java b/final_project/ContactTest.java new file mode 100644 index 0000000..a86e0fd --- /dev/null +++ b/final_project/ContactTest.java @@ -0,0 +1,32 @@ +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; +import final_project.Contact; +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 diff --git a/final_project/final_project/.gitignore b/final_project/final_project/.gitignore new file mode 100644 index 0000000..6abe27b --- /dev/null +++ b/final_project/final_project/.gitignore @@ -0,0 +1,3 @@ +/Contact.class +/ContactList$Main.class +/ContactList.class diff --git a/final_project/final_project/Contact.java b/final_project/final_project/Contact.java new file mode 100644 index 0000000..a83e04c --- /dev/null +++ b/final_project/final_project/Contact.java @@ -0,0 +1,38 @@ +package final_project; + +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 myName + ", " + myNumber; + } +}//Contact \ No newline at end of file diff --git a/final_project/final_project/ContactList.java b/final_project/final_project/ContactList.java new file mode 100644 index 0000000..7d012ff --- /dev/null +++ b/final_project/final_project/ContactList.java @@ -0,0 +1,135 @@ +package final_project; +import java.util.Collections; +import java.util.HashMap; + +public class ContactList { + HashMap theList = new HashMap<>(); + HashMap theNums = new HashMap<>(); + private int size; + + //constructor + public ContactList() { + //contact = new HashMap(); + size = 0; + theList = new HashMap(); + theNums = new HashMap(); + } + + //returns number of elements in the Contact List + 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(name, info); + return true; + }//insert + + 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 + + public Contact findNumber(String number) { + if(theNums.containsKey(number)) { + //System.out.print("Found: " + number + "\n"); + return theNums.get(number); + }//if + return null; + }//find + + + 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 + + public int size() { + return theList.size(); + }//size + + @Override + public String toString() { + return "\nContactList: \n" + theList ; + }//toString + + + public void printAllContacts() { + System.out.print(theList); + }//printALLContacts + + public void searchAllContacts(String target) { + if(theList.containsKey(target) || theNums.containsKey(target)) { + Map map = new TreeMap<>(theList) + return + } + }//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(); +// HashMap person = new HashMap<>(); +// person.put("kelly", "123"); +// int num = "kelly".hashCode(); +// System.out.print(person); +// System.out.print(num); + + System.out.print("testing insert: \n"); + person.insert("sophee", "123-000-8888"); + person.insert("kelly", "123-111-2234"); + person.insert("ally", "333-200-2957"); + person.insert("bob", "444-161-3574"); + + person.findName("sophee"); + person.findNumber("123-456-7890"); + //person.delete("kelly"); + person.printAllContacts(); + } + } +}//HashMap + + + + + + + + + + + + + + + + + + From 0a6ee4f7a73e918ffa338b62ef93fe06bfa7ad53 Mon Sep 17 00:00:00 2001 From: zmckenzie15 <60758576+zmckenzie15@users.noreply.github.com> Date: Mon, 7 Dec 2020 13:54:37 -0800 Subject: [PATCH 3/5] Update README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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. + From d3ffff1153bbef1a57daa805661c855e7e3edd6e Mon Sep 17 00:00:00 2001 From: zoe Date: Mon, 14 Dec 2020 10:02:28 -0800 Subject: [PATCH 4/5] commit- adding running time and analysis --- .DS_Store | Bin 0 -> 6148 bytes final_project/.DS_Store | Bin 6148 -> 6148 bytes final_project/.classpath | 5 +- final_project/.gitignore | 1 + final_project/final_project/.gitignore | 3 - final_project/src/Contact.class | Bin 0 -> 1370 bytes .../{final_project => src}/Contact.java | 4 +- final_project/src/ContactList$Main.class | Bin 0 -> 1166 bytes final_project/src/ContactList.class | Bin 0 -> 3215 bytes .../{final_project => src}/ContactList.java | 90 ++++++++++++------ final_project/test/ContactListTest.class | Bin 0 -> 1994 bytes final_project/{ => test}/ContactListTest.java | 31 +++--- final_project/test/ContactTest.class | Bin 0 -> 1156 bytes final_project/{ => test}/ContactTest.java | 1 - 14 files changed, 85 insertions(+), 50 deletions(-) create mode 100644 .DS_Store delete mode 100644 final_project/final_project/.gitignore create mode 100644 final_project/src/Contact.class rename final_project/{final_project => src}/Contact.java (91%) create mode 100644 final_project/src/ContactList$Main.class create mode 100644 final_project/src/ContactList.class rename final_project/{final_project => src}/ContactList.java (57%) create mode 100644 final_project/test/ContactListTest.class rename final_project/{ => test}/ContactListTest.java (61%) create mode 100644 final_project/test/ContactTest.class rename final_project/{ => test}/ContactTest.java (96%) diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..62e6d1b66f8ab366e727fb5b5c0d6f2c2e634415 GIT binary patch literal 6148 zcmeHKIZgvX5Ud6VmJpId!ubL}SXt%;egKCJ5@^LD!1+eJi>Fb2B&&tYBv!T5Q!_nX zGnxvvw*lDtu)hXY0G4z|eEBdp-*=zcSw)OU=NUb2@rHK{c$sDY9&qj@p74xU+)wzA z*x_^kvFjg(q4zYI6p#W^Knh3!DR2Y@s;Dk6j&PQakOETRv=s2~L!&!(g=1oTIygiN zKwK~!#(DG-#O48FS2!jzLbIe2lWNssSkf79mDd%HiAjf5^I>(fRfl46JI`;C4(k#% zN&zV_Rp30AE3f}I^gsIlDM>3SAO%iJ0b6Xgn>C+QwRQG5ueFVSNB5j>x*O*~;SlAR k80DA?FUMDrlzGkP-0up<#Go@CbfSI+To;)X_-_S%05{4O)Bpeg literal 0 HcmV?d00001 diff --git a/final_project/.DS_Store b/final_project/.DS_Store index a53741b4815096db1822daadfb69d1f8673819d0..dc563e1cf20c89bc829b508a3ac79fd5e7f8bce4 100644 GIT binary patch delta 121 zcmZoMXfc=|#>B)qu~2NHo+2ab#(>?7jI5LYv&c=>V)@LOQkZD1&AB!ku~2NHo+2a5#(>?7izhHMF|thl&m=cli|MmiS#VKaPJUiG0|Nsi z5VJ6pFr+dRPu5_%B?@ITlpw3w+{pZtaWgvyKL^lUAm=;tWPTAx4xnBppmv7M5h81t E0hq%c3jhEB diff --git a/final_project/.classpath b/final_project/.classpath index b3e3c1f..67995dc 100644 --- a/final_project/.classpath +++ b/final_project/.classpath @@ -5,7 +5,8 @@ - + + - + diff --git a/final_project/.gitignore b/final_project/.gitignore index 6f16c47..cb49881 100644 --- a/final_project/.gitignore +++ b/final_project/.gitignore @@ -1,2 +1,3 @@ /ContactListTest.class /ContactTest.class +/bin/ diff --git a/final_project/final_project/.gitignore b/final_project/final_project/.gitignore deleted file mode 100644 index 6abe27b..0000000 --- a/final_project/final_project/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/Contact.class -/ContactList$Main.class -/ContactList.class diff --git a/final_project/src/Contact.class b/final_project/src/Contact.class new file mode 100644 index 0000000000000000000000000000000000000000..9a9b47e42d38df8b604ea2c1bccbad0ab02fe184 GIT binary patch literal 1370 zcmZ`&T~8W86g>mD3){5<0*bX3T1#O?>6dL4%Y!D354JwonE2F;u)>;UAc znwsbt#jv+33LdXC4N zo{AVl@|<7rn$4Yd?eJ9GGAP~8A9&YfNFUr@9(k_iwCfCUx*c{;O_xD!20#q+LFCZ0 z?Aksbbl&qmg(i-yw!^)lOITash@CKe*wY{!Wyf+Xufg!791aM3D#r}5yyE)Pi^L#j(i{sTPFiwT?H~qPg;Z-*j3G>*HwhrG?QX&ANc7>!@IrK|AUV-KP1@ z5);wo!`=`LqDb0C=_e2$4U<-gQTjWLnQk?*Be+9e%Ec_LcgfSC43V>Bj4)?hBYiSL z<`P+B?Gg({^%D87e%?J=bA$}SiP6KEBcu%BZHG zl2tb;THL7yV~q7j0gnBpk`()dFCeh zF-kJILD8a+;ZU72c11tuR3iCFBFj^Wl&2FJlRD6$KtziFAtFQ- u3edxlP3=ojSFT~42vxqLI>Phx%PYL1W1hAvY)>*=9b>q1Bh`*C=-WST0{P7V literal 0 HcmV?d00001 diff --git a/final_project/final_project/Contact.java b/final_project/src/Contact.java similarity index 91% rename from final_project/final_project/Contact.java rename to final_project/src/Contact.java index a83e04c..7f70194 100644 --- a/final_project/final_project/Contact.java +++ b/final_project/src/Contact.java @@ -1,5 +1,3 @@ -package final_project; - import java.util.HashMap; public class Contact { @@ -33,6 +31,6 @@ public void setNumber(String number) { }//setNumber public String toString() { - return myName + ", " + myNumber; + 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 0000000000000000000000000000000000000000..a6c334fd0d87ee55154b8df70082c2b5641dd610 GIT binary patch literal 1166 zcmaJ=T~pIg5IwgPn#L$42#P2cL}{s^Un!*&QK%wlL1%Da)CVUmR|up@O;Tp~Nj~aB znb8@4fIrG{Z`v7PCYp!)vAg%|*^}Mhe}4P|u#D{(A`DZXP1~?OwO!|!H~nnQv3;ZI z*GL`^Kn$WO@wA`u|x}DMO3cFpQ@@)-TxX`mSjoR?~Yi zj4(|66GTP=@i=Z`Jch9=_3WN`K5r?wh1*n%)1lJFdI?M?`zEW@>Nru6;03zg67W>u6Aw@yGvVe zvKA_(vV;Q3(Qq0PbaLssuH_f=TCr5t1))U+Wh^mBr1-&((W2j*389n@|E;9ua-WM{ zTGYx*m7D-wQSd~7$^mH5I>P)^!86fOi9p0P%j&nNC!FgFYC_==j~j0D=#p2I<{naS zjfOM~N!jME=TJjUhI14HKwT&AIvuykH%!sNiA%$=ApSNLv1QxbtyzZWamp1HBSW(6 zP@8Nzo{wpej5KXPgibUWw8rR`rJd0}IDZc5Ti}*y6>gw`YqTo80NSt9Esh%)CX0Cd zl^`RuZ~sK%{W%TRcZ{kNT})=wY4t%D5BD=_TFvwhnwsq$@@lbnnC_xP5tS~g`xLZF zuew;fAh8gnKY)Z2QrN--T9|>23>@hAf+}3B!^Z|XsN*z<9`6ytbG#s860I9}NpuIW WN%si0@QQYsEF>ddQ#tj(p7;xGg9&^9 literal 0 HcmV?d00001 diff --git a/final_project/src/ContactList.class b/final_project/src/ContactList.class new file mode 100644 index 0000000000000000000000000000000000000000..8fb25ac9a7adfcded63d0d87d64957a1d4cd0bcb GIT binary patch literal 3215 zcma)9TUQfT6#gb$62hQ>7({K2N)-|=UJx&#R7DXq1PT<3*AB@62E$A`Gofnl_uDV9 zFI}rIzW89fD!A%eU43({{*C^Ru6}1`NCpUPADB6FW}m&k{e64y34i|m+wTC*;rlQ` z3fks%L(AVSSmu(*I=w@t;b>VWt=mo*)e0Jyv=yy4uNe!y<8#tNLD*Ro^1XsxY4>f> z(eu3{n!Pxt6;cZ7rt}3vbBdNwFu2uXz}s?NPC1rtETqyEF{B3ROa{vomu&^rw*HVF zl~Dz?1G=F*g9@rTI%oK1$jpf-s?exHMMD_P3YxYci=qjQbx^QdMGb1@s#Qguw`x-n zMZJQZY2A?V=7cq^&E*-dIc;XO{ETMl^4Z_4b{2I)+E*F4B!|#zb;A}GX*$|bA>}f! zJ_(&SB*KF#4&ktZ`m7X!95%HYQHR%XG>jt~RGNBVJ7QTy2Rg}*S!Dd( zUU=Q?ogm!~;|Xm!6+u!#%cWu=uV*z!#B;)-ydu{VjiMX9Vf0X77v;u-Dvsf}f|`Q# zwF%mKDl-wBRIn#w#tm&*#7!%1xSYlp^c7+BgmH=oD~cXPA5Kdd&-`!RW+ZRtRHQJ# zj0-a3GZpv>Xt2)U)-4v3L@Z_BA`lhzvY?S}%$uyA%KB6LhADQ@J@$iNFcBu3%ebDC zL2T=UZR1F0Hmu?bMwr=xU}i^xr~fUFs2kB`oxpPFXl$8|eym`+?b z;_USJBB#i*R$vKca8t!C+$K`3P!L8=L3c3s5_8*NPe~VdRlEaDLBugVdsci$XC-M> zDf{^3y1*PPqmnHl=R!7u1&)SjU^bqMyAX8=acL8>3aWU)eO6f>jc)T?$me~Rwrn{z z?J*deI%?e+$6S*wG%LFpI2FOW9Eed;ZyUEWwT^uqixF5!Q3U-v4 zOPj`miU)Ye>0Qt)TgZ)VJX{Uq0|f`lhZ&ILa@e$%HRtmEtSC6TX@v2Sf>(n^`TT^* zi6N|#4RPC!#p5h)W1da7KcLKH(Qx!-Q8G@2@wtM%WsjQ;6hx=YqLmfHx}4jM0kwMM zDFy1NVF+s|ui3V+!}x{(E6yM}zuU(+eA(#Utv(}cXH3XEZ5-s6ql#Zp`Nt0lpTb;) z5aE@dlfZLGepI*{%EL{fDsaWI)z5;qmAlC!hXEMCnih_55-?RSIxb}#II;ct|I;e z+U2s#UAA!<^Oif-mygi!3)-6#tLUnFl6;A#u9x1<33ulO`eu_|Yv|9o9=lg@_PRWp zbXV0+7^}*~-Q#l7f*5wAi`PE1q91J-1TX)jq^ z#2Z|Ncp`@LxWE_}xm$y(uDT`~4B?WW@Esb3_)4bcCj5x(d&|pzpzo>jw1jYnt8F`R z9wD|)7eUNBTtd+1BaqRkXDg$OR*V&svU03$#_DCPw&r#1`eU4QHP`?l&h7n_@&z)p$>*3@!%XwrtGKa>J5*8@m?xB1VEu%48ZG?6 zc!;0aBnHsK)US|sSzsP5BPCi!Fjs;~5n5w=2$Lh!2YZ5dsaiyWT}4h-g;&k8Z@>)8 zRU0W)EoZoYeo%5vyB3MPd7j8UM~lQR^$YsC67bbh@^!D&hi7Rmebti+&r81CTv3

B+3mcWe0Ph}?KT124Fqk##|$OsUI?GyQ-+ZJz<(@8!uU+a`GSuje2K4k Smt*j2{(VdH@AzCTpZ@_7TEhwe literal 0 HcmV?d00001 diff --git a/final_project/final_project/ContactList.java b/final_project/src/ContactList.java similarity index 57% rename from final_project/final_project/ContactList.java rename to final_project/src/ContactList.java index 7d012ff..5056613 100644 --- a/final_project/final_project/ContactList.java +++ b/final_project/src/ContactList.java @@ -1,10 +1,11 @@ -package final_project; import java.util.Collections; import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; public class ContactList { - HashMap theList = new HashMap<>(); - HashMap theNums = new HashMap<>(); + Map theList = new HashMap<>(); + Map theNums = new HashMap<>(); private int size; //constructor @@ -15,7 +16,10 @@ public ContactList() { theNums = new HashMap(); } - //returns number of elements in the Contact List + /* + * 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))) { @@ -28,10 +32,15 @@ public boolean insert(String name, String number) { } Contact info = new Contact(name, number); theList.put(name, info); - theNums.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"); @@ -41,15 +50,23 @@ public Contact findName(String name) { 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)) { - //System.out.print("Found: " + number + "\n"); 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); @@ -62,25 +79,43 @@ public void delete(String nameORnumber) { }//else }//delete + /* + * Running time: O(1) + * Analysis: returns the size of the theList; + */ + public int size() { return theList.size(); }//size - @Override - public String toString() { - return "\nContactList: \n" + theList ; - }//toString + /* + * Running time: O(n log n) + * Analysis: returns the names of everyone in the list, sorted by name; + */ - public void printAllContacts() { - System.out.print(theList); + 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) { - if(theList.containsKey(target) || theNums.containsKey(target)) { - Map map = new TreeMap<>(theList) - return - } + //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 @@ -96,22 +131,19 @@ private static boolean isNumeric(String strNum) { public static class Main { public static void main(String[] args) { ContactList person = new ContactList(); -// HashMap person = new HashMap<>(); -// person.put("kelly", "123"); -// int num = "kelly".hashCode(); -// System.out.print(person); -// System.out.print(num); - System.out.print("testing insert: \n"); - person.insert("sophee", "123-000-8888"); + 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.findName("sophee"); - person.findNumber("123-456-7890"); - //person.delete("kelly"); 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 0000000000000000000000000000000000000000..76b8615e86d3c72d6a54210cfb4262b4ba5daf27 GIT binary patch literal 1994 zcmZ`(ZC4vb6n-WI5|-hmDT0tvOF^3eAqk-`G_(p7EEs7mlv;eLOITnzVHbBd9`(CF z$a9o(^c;VHKg#1Xvr7_a`XxK}&fNRF+?o9Q-(UX#c!;9}Vgmgut`nHmpkn*Mw&e#2 z#03V9&7aJC&2$d)&-RY3YQS^V%jX2rl>^%`Yi~|HR~^Z>G%5>pE!vJ9JQnE4WOoGO zEAGB!paVS;2_zHf6&QJMy#a}yZjgvXC%TAUu^nr(ezIqI+vZ-)5=d3ts#)7HJzK?5 zG9Db+zQDCg3l}Add^&wAczG&dto~fJP6OL@`~*G}xZaf7*detSbtkY-tR368*?!4! z+`!aD8reI{AJ-`_zib`2o>flbhC(oFwO^9BDIkk;rQH18d%61$779wtEs1g5rYpAN zTORGalc_X;w*t?04$JRmvb#x4vdTX)J-3#`Czo3n83vTMW;^?v<_TRHsJIPoTDStA zl9daWk#L2LK$0+q8n z2Ig@ufxFyqJ9vrvcp#8Cw1QB~U?%&nC5p{Mi82-`KEz%9v2NBl_Dh~duq_Q*h)6t^ z_*8jfXixOTQk|D1mX#tSQl#Z{om!snIs(J*aY&%AF@~tsJU*9rs`PX#Jvy7jMl`=- zv6w3sOCUU`Iv{+u$=!$0x|X2 zxk_-&KMDSJGg{`Z;CEo^EsUwZAz!~m-=FCJow*pU@wZRcClTlQe%7U!lVJ_6V~`Pz zWWEDKT*ny=V}z?Nu15J)D7z8LWDCO7ALvh|Q)6fN=#^eiq&`;bCUT116jl#<*|QH5 z#BZWcHqh@7J=Va?M3_g+#kigffzFVvOrIl{N>87mbdCj`CgP)WeAdJqqDvr(!R~!j zH%x64RHkr;!hR91L3Jy5LX`rmZ5h-f200Byp^q*zNR5%o+69&Mt5inyxJF22lvL8B zas#(8h8f&!p_6OSnP|}YqAi`Lq@zYX6uNze%Ecmk$%1g;w>h{8il1z;e5hgh^R@^U z$E++L*NwkQZE>E9>2ti)aX4!gzrN~shEvXB08^AWO_4J#0>>jzNiyH!JMH)PZQ+;o j?E?lC+!@~dcJVz&wTWnGiUoEpwn!UnNIRf_7!Lmjh;@dD literal 0 HcmV?d00001 diff --git a/final_project/ContactListTest.java b/final_project/test/ContactListTest.java similarity index 61% rename from final_project/ContactListTest.java rename to final_project/test/ContactListTest.java index 3105c83..90d1e79 100644 --- a/final_project/ContactListTest.java +++ b/final_project/test/ContactListTest.java @@ -1,9 +1,9 @@ -import final_project.Contact; -import final_project.ContactList; 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(); @@ -12,22 +12,25 @@ 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.findNumber("123-456-7891")); + 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 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 () { @@ -44,8 +47,12 @@ public void testInsert () { } @Test - public void testSize () { + 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 0000000000000000000000000000000000000000..bd4d09226cd4f4600854d01a2ebc79d1d8ac902a GIT binary patch literal 1156 zcmZvaZBNrs7>4gN1}mk&C~OD_1K-#SFhr-!p$Q@Amjx3bOZ-I2sH0?Su{|^KXZZz; zCjJ0_l<_`m8AX;Rr|0E)p8I-U{`~#<8^9a9O(7vLw&%IhYRY3fkSQbu(ihfOtK7ES zR{7)Uh24|_BRh`k$aexm`9eb=x#ykPI)*T6U>G9;lXb_n54xRG+dsBW+qQsN_nKC_ zVfl_aN0&)??gRqk^_XOh1d`GpY$zKj=ML#F7 zny=rcd?bCxZPo7I6dKBB!N5Z-3Zz=LJg_>%GSl@ykVd`r9=1hy{?Ji=qr zSiRH!m#)=jW_K9Evd0;sn~>qDfoFVVyOU*vF3L ze^Xhl8`waZQG%PSG6QN-XlS57ypC1n{ldUYWAf;oovZ3096>ttYz(A5a&L7tlPi6iE|HH*=Xy3U>KtfD;BzaG(2ysZZv#nYm_B&FRt==6_(x%y9FBn_CH! z4xoU+FT>DF45{R@VVFqHz%*8or>sC>pl}cgm*T=Dvv`Fyvlz*j%*`uonVa_@<{1){ zFfap?7z>nN!7PfHi@}uoFu6WVWgyI91e1-!n6Ie2eJA;eUNaUMcZsUGm{zv0rT4XJ IWK3Y^A8#Jr@&Et; literal 0 HcmV?d00001 diff --git a/final_project/ContactTest.java b/final_project/test/ContactTest.java similarity index 96% rename from final_project/ContactTest.java rename to final_project/test/ContactTest.java index a86e0fd..9f6b5be 100644 --- a/final_project/ContactTest.java +++ b/final_project/test/ContactTest.java @@ -1,7 +1,6 @@ import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; -import final_project.Contact; import static org.junit.Assert.assertEquals; public class ContactTest { From e03c9877bfe1ee449817f91a6db9016511d845b2 Mon Sep 17 00:00:00 2001 From: zoe Date: Mon, 14 Dec 2020 10:16:40 -0800 Subject: [PATCH 5/5] commit- fixing some stuff- running time/analysis --- final_project/src/ContactList.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/final_project/src/ContactList.java b/final_project/src/ContactList.java index 5056613..569ce27 100644 --- a/final_project/src/ContactList.java +++ b/final_project/src/ContactList.java @@ -40,7 +40,6 @@ public boolean insert(String name, String number) { * 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"); @@ -54,7 +53,6 @@ public Contact findName(String name) { * 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); @@ -66,7 +64,6 @@ public Contact findNumber(String number) { * 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); @@ -83,7 +80,6 @@ public void delete(String nameORnumber) { * Running time: O(1) * Analysis: returns the size of the theList; */ - public int size() { return theList.size(); }//size @@ -92,7 +88,6 @@ public int 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); @@ -108,7 +103,6 @@ public void 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()) {