Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java please: This lab will give you practice using many of the Java String library functions. You are required to parse and validate input

In Java please:

This lab will give you practice using many of the Java String library functions. You are required to parse and validate input records from a text file. The name of the input file will be passed to your program using command line arguments. Each line of input will contain a single record containing:

Firstname, Lastname, Gender, Age, Phone Number, Email Address

E.g. Jimmy, Smith, mAlE , 88, (564) 375-9090, hammondmaster@blues.com

  • Firstname: Should only contain upper and lower case letters.
  • Lastname: Should only contain upper and lower case letters.
  • Gender: male or female are the only two values. This field is not case sensitive so upper and lower case letters can be used.
  • Age: Must be between 1 and 130.
  • Phone Number: (xxx) xxx-xxxx (each x can only be a digit) just confirm that there are 10 digits.
  • Email Address: LettersandDigits@LettersAndDigits.net|com The email address must start off with a letter, include only letters, digits, periods and the @character.

Each of the above fields will be separated by a comma. You are required to:

  1. Read in each line of input using the Scanner nextLine() method. You can assume that the input file will have no more than 100 records. You will need to declare an integer variable to keep track of how many records are actually stored in your 1D array of strings (described below). You are free to use an ArrayList if you want to avoid using the extra variable used to track the actual number of array locations used.
  2. Parse the line of input using the String split() method
  3. Validate each field according to the description in the field list above. Create a different method to validate each field. The method that validates the first name can also be used to validate the last name. If the line of input has an error, immediately output the field and the error. If the field has no errors, format and store the input record fields in an 1D array such that when printed, all the fields will line up in columns. You may find the following String and Character methods helpful:
    • charAt()
    • indexOf() trim()
    • format()
    • toUpper() toLower() length()
    • substring() split()
    • Character.isDigit()
  4. After all the input has been processed, output the valid input stored in the 1d array to the console. This output should have neatly aligned columns.

Grading Description

  • Level 1 (10 pts): Your program should obtain the filename from the command line argument, use the split function to parse the input, then store the input fields into a formatted string and store each string into the 1D array. Finally, output the array to the console.
  • Level 2 (15 pts): Complete level 1 and validate the Firstname, Lastname and Gender fields. If errors are found, output the errors but do not store records with errors in the array.
  • Level 3 (20 pts): Validate all fields.

Hint

String output = String.format("%-20s%-20s%-10s%10d", "William", "Bryant", "Male", 22 ); String sFirstname = Helen;

String sLastname = Bryant;

String sGender = female;

int age = 9;

String output2 = String.format("%-20s%-20s%-10s%10d", sFirstname, sLastname, sGender ); System.out.println(output);

System.out.println(output2);

Produces:

William Bryant Male 22 Helen Bryant female 9

The first %-20s means to output the first value (i.e. Kelvin) into field of 20 characters that is left justified (the minus sign means left justify and the s means that the corresponding value (Kelvin) is of type String. %10d is a right justified integer value. For more examples, see: https://dzone.com/articles/java-string-format-examples

records.txt file:

Dara,Sampson, female,16, (936)765-7152,DSampson@Sampson.net Bethany,Williamson, female,91, (555)450-5159,BWilliamson@Williamson.com Lamar,Collins, male,73, (413)476-3683,LCollins@Collins.com Callie,Conley, female,49, (629)905-7544,CConley@Conley.net Illiana,Duncan, female,-89, (260)520-7926,IDuncan@Duncan.com Arsenio,Brady, male,64, (406)961-5429,ABrady@Brady.net Allen,Sheppard, male,28, (992)989-3407,ASheppard@Sheppard.com Scarlett,Humphrey, female,84, (360)472-5923,SHumphrey@Humphrey.net Astra,Mcclain, female,84, (237)617-1223,AMcclain@Mcclain.com Blaze,Burton, male,52, (749)177-6495,BBurton@Burton.net Signe,Anderson, male,78, (848)424-5349,SAnderson@Anderson.net Fiona,Mclaughlin, female,98, (545)291-8786,FMclaughlin@Mclaughlin.net Unity,Lara22, female,54, (803)525-9084,ULara@Lara.net Judah,Cox, male,41, (906)230-4178,JCox@Cox.net John,Moses, male,2, (324)767-2333,JMoses@Moses.com Dustin,Tate, male,11, (986)434-4278,DTate@Tate.net Reuben,Madden, male,110, (163)541-9030,RMadden@Madden.net Leandra,Hayden, female,31, (675)609-2600,LHayden@Hayden.net Nasim,Hooper, male,77, (388)115-7233,NHooper@Hooper.net Sylvester,Solomon, male,125, (324)428-1809,SSolomon@Solomon.net Tana,Blackburn, female,112, (298)497-3780,TBlackburn@Blackburn.net Summer,Meyers, female,179, (486)180-9197,SMeyers@Meyers.net Whitney,Juarez, female,97, (692)784-9614,WJuarez@Juarez.net Camille,Acosta, female,79, (393)431-9713,CAcosta@Acosta.net Philip,Howard, male,78, (598)949-3444,PHoward@Howard.net Colette,Ramirez, female,124, (883)396-1123,CRamirez@Ramirez.net Aspen,Norris, malE,39, (451)444-7899,ANorris@Norris.com Porter,Nash, male,7, (909)548-2234,PNash@Nash.com Steel,Cantu, male,39, (334)479-5217,SCantu@Cantu.com Edan,Nichols, male,102, (343)324-4381,ENichols@Nichols.com Kylynn,Morales, female,38, (777)806-4346,KMorales@Morales.com Nissim,Holloway, male,97, (849)607-8895,NHolloway@Holloway.net Jermaine, Mccullough, male,29, (123)340-y962,JMccullough@Mccullough.net Cheyenne,Cruz, female,45, (755)357-3014,CCruz@Cruz.net Jescie,Valenzuela, male,15, (940)515-3229,JValenzuela@Valenzuela.com Ulric,Rosario, male,6, (170)249-9049,URosario@Rosario.com Kirby,Morgan, male,125, (348)367-4318,KMorgan@Morgan.net Dean,West, male,34, (878)502-9705,DWest@West.com Tyrone,SEARS, male,96, (137)565-3953,TSears@Sears.com Robin,Powell, male,15, (403)713-4305,RPowell@Powell.snet Ashton,Chen, male,126, (513)198-3686,AChen@Chen.net Sybil,Richard, female,73, (580)576-2674,SRichard@Richard.net Ivan,Mack, MALE,123, (865)873-7816,IMack@Mack.com Maxwell,Lambert, male,26, (966)447-9315,MLambert@Lambert.com Christian,Kemp, male,35, (219)714-1970,CKemp@Kemp.com Sylvia,Webster, female,28, (191)445-7773,SWebster@Webster.net Holly,Ashley, female,47, (193)508-1015,HAshley@Ashley.net Inga,Newton, female,38, (916)500-6672,INewton@Newton.net Rana,Avila, female,38, (631)379-3065,RAvila@Avila.net Chase,Hyde, male,69, (431)852-7202,CHyde@Hyde.com Wendy,Fulton, female,120, (713)381-3293,WFulton@Fulton.net Lionel,Cardenas, male,75, (848)624-8726,LCardenas@Cardenas.com Martena,Madden, female,28, (560)658-4629,MMaddenMadden.net Charles,Franks, male,57, (893)858-3520,CFranks@Franks.net Leila,Carter, female,12, (293)611-1741,LCarter@Carter.com Alana,Herrera, female,10, (759)510-2979,AHerrera@Herrera.com Tucker,Tate, male,7, (117)982-9240,TTate@Tate.com Pearl,Snow, female,128, (918)730-5402,PSnow@Snow.com Fleur,Schneider, female,14, (714)970-9717,FSchneider@Schneider.net Venus,Herman, female,51, (864)194-8894,VHerman@Herman.com Mallory,Hood, female,40, (674)636-9191,MHood@Hood.net Uriel,Figueroa, male,48, (422)539-9903,UFigueroa@Figueroa.net Patricia,Adams, female,110, (812)852-2940,PAdams@Adams.com Katelyn,Gentry, female,52, (904)797-6468,KGentry@Gentry.com Fatima,Reid, female,111, (791)394-6525,FReid@Reid.net Mari,Cain, male,28, (735)285-6009,MCain@Cain.net Ivana,Blake, female,60, (113)573-1740,IBlake@Blake.com Wilma,Coffey, female,101, (464)169-1041,WCoffey@Coffey.com Kevyn,Cleveland, male,41, (180)786-9790,KCleveland@Cleveland.com Chaney,Cannon, male,111, (881)401-4358,CCannon@Cannon.com Adria,Charles, female,125, (373)194-5230,ACharles@Charles.com Harrison,Fulton, male,60, (418)590-9978,HFulton@Fulton.net Shad,Simpson, male,8, (434)527-6264,SSimpson@Simpson.com Channing,Walton, male,28, (605)347-2931,CWalton@Walton.net Yvette,Tanner, female,65, (912)806-8030,YTanner@Tanner.com Amos,Burton, male,106, (156)870-5196,ABurton@Burton.net Deanna,Gonzales, female,85, (572)163-8133,DGonzales@Gonzales.com Thaddeus,Gentry, male,7, (897)757-7992,TGentry@Gentry.com Darrel,Moran, male,68, (637)225-5222,DMoran@Moran.com Clementine,Ferrell, female,42, (790)571-3885,CFerrell@Ferrell.net Dieter,Cantrell, male,72, (238)726-4268,DCantrell@Cantrell.net Samson,Hobbs, male,89, (100)448-7011,SHobbs@Hobbs.net Kay,Mccullough, female,27, (492)831-9151,KMccullough@Mccullough.net Griffin,Mcpherson, male,64, (767)682-6812,GMcpherson@Mcpherson.net Dolan,Ball, male,128, (246)152-7614,DBall@Ball.com Wilma,Richardson, female,38, (655)672-1060,WRichardson@Richardson.com Savannah,Meyer, female,115, (248)996-9555,SMeyer@Meyer.com Eleanor,Carroll, female,58, (181)659-5279,ECarroll@Carroll.com Meghan,Weber, female,124, (516)512-2581,MWeber@Weber.net Yvonne,Cervantes, female,15, (203)656-5170,YCervantes@Cervantes.com Leslie,Rojas, female,87, (939)764-1118,LRojas@Rojas.com Olivia,Downs, female,119, (933)860-5889,ODowns@Downs.net Xanthus,Suarez, male,35, (249)641-7263,XSuarez@Suarez.com Asher,Riley, male,51, (298)980-9296,ARiley@Riley.com Walker,Lindsey, male,13, (578)654-3531,WLindsey@Lindsey.com Hayfa,Sanchez, male,80, (911)391-4830,HSanchez@Sanchez.net Kimberly,Cook, female,, (498)185-6137,KCook@Cook.com

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

Outline the main areas covered by the Landrum Griffin Act of 1959.

Answered: 1 week ago

Question

What is involved in the administration of a labor agreement?

Answered: 1 week ago

Question

What are topics included in virtually all labor agreements?

Answered: 1 week ago