1. Engineering
  2. Computer Science
  3. programming project 2 part a arraylists part a ...

Question: programming project 2 part a arraylists part a ...

Question details

Programming Project 2 Part A –

ArrayLists Part A - ArrayLists

adds Excel (Unlicensed Product) Home Insert Page Layout Formulas Data Review View Help Tell me what you want to do Calibri . Wrap Text General E Copy Paste Merge & Center 40 00 Conditional Format as Cell 00 .0 Format PainterBIUA Formatting- Table- Styles Clipboard Font Alignment Number x 627 Walford Ave first name last name emailcompany address city Char Paul county state zip phone1 phone2 web KinesCharHines W Tc Indu: 3 Aspen St Worcester Worcester MA CartanPaul.carta Box, J Calv 9390 S Ho Albany Dougherty GA Lary Hagele Mhagele@ Ninas Indi 627 WafoDalas Dallas TX Frey 1602 508-429-8 508-843-1 http://www.wtcindustriesinc.com 31701 229-735-3 229-365-9 http://www.boxjcalvinesq.com 32922 321-749-4 321-632-4 http://www.matriccianialbertjjr.com 75227 214-339-1 214-225-5 http://www.ninasindiangrsvideos.com 11758 516-948-5 516-357-3 http://www.woodbridgefreepubliclibrary.com Joe lary@ Matriccian 8597 W NE Cocoa Brevard FL Mark Bill Bill_frey@ Woodbrid 54169 N M Massapeqi Nassau NYmembers Excel (Unlicensed Product) File Home Insert Page Layout Formulas Data Review View Help Tell me what you want to do Calibri General B 1 u . 田· O-A . | s-96 , 留 Conditional Format as . Cell FormattingTableStyles 트 Merge & Center . Format Painter Clipboard A1 first name I) 1 first_namel last_name em company_address city 2 James Butt county state Zl phone1phoe2 web 70116 504-621-8 504-845-1 http://www.bentonjohnbjr.com 48116 810-292-9 810-374-9 http://www.chanayjeffreyaesq.com jbutt@gma Benton, Jo 6649 N Blu New Orlea Orleans LA 3 Josephine Darakjy josephine_ Chanay, Je 4 B Blue Ri Brighton Livingston MI Venere art@vener Chemel, Ja8 W Cerrit Bridgeport Gloucestei NJ 5 Lenna Paprocki lpaprocki@ Feltz Printi 639 Main SAnchorage Anchorage AK 6 Donette Foller donette.fc Printing Dii 34 Center Hamilton Butler OH 7 Simona Morasca simona@n Chapman, 3 Mcauley Ashland Ashland OH 8014 856-636-8 856-264-4 http://www.chemeljameslcpa.com 99501 907-385-4 907-921-2 http://www.feltzprintingservice.com 45011 513-570-1 513-549-4 http://www.printingdimensions.com 44805 419-503-2 419-800-6 http://www.chapmanrosseesq.com 60632 773-573-6 773-924-8 http://www.morlongassociates.com 95111 408-752-3 408-813-1 http://www.commercialpress.com 57105 605-414-2 605-794-4 http://www.truhlarandtruhlarattys.com 21224 410-655-8 410-804-4 http://www.kingchristopheraesq.com 19443 215-874-1 215-422-8 http://www.dorljamesjesq.comm 11953 631-335-3 631-677-3 http://www.rangoniofflorence.com 90034 310-498-5 310-254-3 http://www.feinerbros.com 44023 440-780-8 440-579-7 http://www.buckleymillerwright.com 78045 956-537-6 956-841-7 http://www.rousseauxmichaelesq.com 85013 602-277-4 602-953-6 http://www.centurycommunications.com 37110 931-313-9 931-235-7 http://www.boltonwilburesq.com 53207 414-661-9 414-377-2 http://www.tmbyxbeecompanypc.com 48180 313-288-7 313-341-4 http://www.farmersinsurancegroup.com 61109 815-828-2 815-426-5 http://www.postboxservicesplus.com 19014 610-545-3 610-492-4 http://www.sportenart.com 95111 408-540-1 408-813-4 http://www.cnetworkinc.comm 75062 972-303-9972-896-4 http://www.ingallsdonaldresq.com 12204 518-966-7518-448-8 http://www.franklinpeterlesq.com Art 8 Mitsue Tollner mitsue_tol Morlong A 7 Eads St Chicago Cook 9 Leota Diard leota@hot Commerci 7 W Jacksc San Jose Santa Clar. CA Wiesersage_wies Truhlar An 5 Boston A Sioux Falls Minnehah SD Marrierkris@gmai King, Christ 228 Runan Baltimore Baltimore MD 12 Minna Aigon minna_am Dorl, Jame 2371 Jerro Kulpsville Montgome PA Maclead amaclead( Rangoni O 37275 St FMiddle Isla Suffolk NY Kiky a kik:y.caa ir Bro hs A:ls CA Akl 16 Cammy Albares calbares@Rousseaux 56 E More Laredo WebbTX 17 Mattie Poquette mattie@ac Century Cc 73 State R Phoenix Maricopa AZ 18 Meaghan Garufi meaghan@Bolton, Wi 69734 E C Mc Minnvi Warren TN 19 Gladys Rim gladys.rim T M Byxbe 322 New HMilwaukee Milwaukee Whobrey yuki_whot Farmers In 1 State Ro Taylor Wayne MI 23 Veronika Inouye vinouye@ C4 Netwo 6 Greenlea San Jose Santa Clar CA WillardKolmetz willard@h Ingalls, Do 618 W Yak Irving Dallas TX Maryann Royster mroyster@ Franklin, P 74 S West Albany Albany NY lusarski alisha@slu Wtlz Powe 3273 State Middlesex Middlesex NJ 25 撈训6 /32.458漳132.435.浮http://yrww.widzp()weniim.com 662-6 715-530-9 http://www.ledeckydavidesq.com All Cha Ezekiel Chui ezekiel@cl Sider, Don. 2 Cedar Av Easton TalbotMD 90991 Tho New York New York NY bfigeroa@ Clark, Rich 386 9th Av Conroe Montgome TX GG218 1:1 3 31913- 2py 1 hting www.prufessoréalinnang: c.ex pm 21601 410-669-1 410-235-8 http://www.siderdonaldcesq.com 10011 212-582-4 212-934-5 http://www.upullit.com 77301 936-336-3 936-597-3 http://www.clarkrichardcpa.com Bernardo Figeroaremoves - Excel (Unlicensed Product) File Insert Page Layout Formulas Data Review View Help Tell me what you want to do Home Calibri ab Wrap Text General Copy Paste B 1 u-1田.1Cr. A·ーΞ Ξ 트衫固Merge & Center. | $. % , 留£2 | Conditional Format as Cell | Insert Format Painter Formatting TableStyles Styles Clipboard Font Alignment Number A1 firstname - C: t) 1 first_namelast_name email company_address city 2 Sage Wieser sage_wies Truhlar An 5 Boston A Sioux Falls Minnehaha SD 3 Yuki Whobrey yuki_ whot rm n1 State Ro Taylor Wayne MI 4 Willow uskowkusko@-U Pull It 90991 Tho New York New York NY 5 Valentine Gillian valentine_ Fbs Busine 775 W 17t San Antoni Bexar TX 6 Emerson Bowley emerson.b Knights Inr 762 S Mair Madison D W 7Delmy Ale delmy.ahle Wye Techr65895 S 1 Providence Providence RI 8 lene Eroman ilene.erom Robinson, 2853 S Cer Glen Burni Anne Arun MD 9 Viva Toelkes viva.toelke Mark Iv Pri 4284 Dorit Chicago Cook IL 0 Stephen Emigh stephen_e Sharp, J De 3777 E Ric Akron Summi OH 1Lisha Centini lisha@-cer Industrial 64 5th Ave Mc Lean Fairfax VA county state zip phone1 phone2 web 57105 605-414-2 605-794-4 http://www.truhlarandtruhlarattys.com 48180 313-288-7 313-341-4 http://www.farmersinsurancegroup.com 10011 212-582-4 212-934-5 http://www.upullit.com 78204 210-812-9 210-300-6 http://www.fbsbusinessfinance.com 53711 608-336-7 608-658-7 http://www.knightsinn.com 909 401-458-2 401-559-8 http://www.wyetechnologiesinc.com 21061 410-914-9 410-937-4 http://www.robinsonwilliamjesq.com 60647 773-446-5 773-352-3 http://www.markivpressltd.com 4302 330-537-5 330-700-2 http://www.sharpjdanielesq.com 22102 703-235-3 703-475-7 http://www.industrialpapershreddersinc.comMembership_Processor - Notepad File Edit Format View Help import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.scanner; public class Membership_Processor f public static void main(string[] args) throws FileNotFoundException { PartA) 2 Always add a useful Javadoc method header Give me a preview of what the function does Tell me what to look for in the function public static void PartA() throws FileNotFoundException { ArrayList<Person> membership readNames(); System . out.println(string . format (Read Total of %d names, membership. Size())); * Reads file of names * @return ArrayList of Person class * @throws FileNotFoundException public static ArrayList<Person> readNames() throws FileNotFoundException { // Open scanner on file members.csv File f new File(members.csv); Scanner sc new Scanner(f); // TODO: create ArrayList of Person class variable p // Discard first line its the headers first name last name email etc sc.nextline(); // Loop through lines of the file while (sc.hasNextLine()) [ // Get the next line String line - sc.nextline(); Scanner scLine -new Scanner(line); // This allows us to use comma as the delimiter instead of whitespace scLine.useDelimiter(,); // Scan the line for the names & emails string first = scLine . next(); String last scLine.next(); String email -scLine.next(); // TODO: put the person into the ArrayListMembership Processor Notepad File Edit Format View Help /I TODO: return the ArrayList you defined return new ArrayList<Person>(); * Testing code - do not modify @param membership public static void testPartA(ArrayList<Person> membership) { // Test for correct total # of names if (membership.size() !=445) { System.out.println(Wrong number of names. There should be 445 after all removals and adds); return; // Test all 10 names removed for (Person p membership) if (p.getEmail().contains(-)) ( System . out, printin(String . format (oops didnt remove person %s %s %s, p.get FirstName(), - p.getLastName(), p.getEmail())); return; // Test that only 5 names added int count for (Person p membership) if (p.getEmail().contains(*)) count++; if (count != 5) { System.out.println(didnt add the right number of names); return, // Check sorting & overall work at specific random items int[] memberindexes = { 0, 10, 20, 30, 40, 400 }; tring] expectedEmails- { Bill **, , amber , , , tasia  j; for (int í = 0; i < memberindexes.length; 1++) { String memberEmail - membership.get (memberIndexes[i]).getEmail(); if (ImemberEmail.equals(expectedEmails[i])) system . out, printin(string . format (Index %d expected %s but found %s, memberIndexes [1], expectedEmails[i], memberEmail)); System.out.println(Congrats - you passed all tests);Person Notepad File Edit Format View Help import java.util.*; import java.io.*; * Programming Project 2 * Part A ArrayLists *@author * Represents a person - first, last, email public class Person private string firstName; private string lastName; private string email; public Person(String firstName, string lastName, string email) this.firstName-firstName this.lastName-lastName; this.email-email; * @return the firstName public string getFirstName() { return this.firstName; * @param firstName the firstName to set public void setFirstName (String firstName) { this.firstNamefirstName; *@return the lastName public string getLastName() { return this.lastName; *@param lastName the lastName to set public void setLastName(string lastName) [ this. lastName = lastName ; x R * areturn the emailmodify this function to accept a parameter of a String filename, so it can be used for any filename. Modify its caller so that the function sworks on members.csv. Make sure to update its Javadoc header accordingly. o Modify readNames() to store each Person where indicated. o Verify that your code read 450 names. . Remove Names o Add a new call to readNames (removes.csv). Call this returned ArrayList removes. o Add a print Read Total of <#> removes to verify you read 10 removes. In the next steps you will take each of the removes, look for it in the membership, and remove it if found or print an error if not found. For Person class objects, we choose to use email names to test for equality because these are unique to a Person. o o Run the code. Did you find any of the 10 names to delete? Implement the Comparable interface on the Person class. Modify the Person class declaration to tell Java it will support the Comparable interface. Note this is parameterized which means you need to put the object type in the<>brackets just like you do for ArrayList. Note the red x reminding you that you must now add the compareTo method to the Person class. You must exactly match the compareTo interface definition (function name, parameters, return type). Test only the email field and matclh the compareTo interface return type definition. Now, replace .equals with .compareTo in your nested loops written above for removed in the above step. o o Add a print statement Total of>names after removals and verify you removed 10 Persons and now only have 440 left.Add a print statement Total of <#> names after removals and verify you removed 10 Persons and now only have 440 left. Add Names o Add another new call to readNames (adds.csv). Call this returned ArrayList adds Add a print statement Read Total of <#> adds and verify you read 5 adds. Write another loop similar to removes. For each member to be added, check for an existing member with the same last name only, and add it immediately after that member. Note this is a different criterion than used for the removes. Make sure to only add each name once. Print a message if you cant find a name and include the email name youre adding. o o Print out Total of <#> names after adding and verify its 445. Sort Now that you have implemented Comparable you can sort the list without having to write almost anything. Write the code to use the Collections class to sort the ArrayList. o *Check your work Add a call from partA() to testPartA() to double check your work. This is similar to the types of tests Practicelt runs on your code. If you have errors use the debugger to see where the problem is exactly in your data and work backwards to fix. o o Check the total number of names is correct at each step o Check your compareTo is sorting based on email names Check you are not accidentally insert or removing more than once (there are names to trip you up if you should not take care of this) o Use intelligent variable names. Intelligently naming all your variables can make the difference between readable bug-free code and illegible broken code. By convention, classes should begin with Uppercase letters, while regular variables should begin with lowercase letters. .* return the firstName public String getFirstName() { return this.firstName; 末朱 param firstName the firstName to set public void setFirstName(String firstName) { this. firstName = firstName ; * return the lastName public string getLastName() [ return this.lastName * @param lastName the lastName to set public void setLastName (String lastName) this.lastNamelastName; @return the email public String getEmail() return this.email; *@param email the email to set public void setEmail (String email) ( this.email - email; * Print out the name public string tostring) return Person [firstNamethis.firstName , lastName- this.lastName, email-this.email + ];

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution