JAVA: Use text file to Create a .java file that reads in this file into an array
ID: 3709440 • Letter: J
Question
JAVA: Use text file to Create a .java file that reads in this file into an array. Make the array of size 100. In a loop, ask the user for their birthdate. Check to see if there is a match with anyone in the array. If there is a match let the user know who it is. If there is no match let the user know there was no match.
TEXT:
Names & birthdays:
James Bond: 02 04 1989
Janis Ian: 01 08 1991
Michael Murray: 09 17 1991
Billy Jean: 10 18 1971
Joe Shmoe: 08 09 2009
Harry Potter: 07 31 1980
Bryan Cranston: 11 27 1964
Neil Armstrong: 09 14 2015
Jake Smith: 12 01 1990
Derek Rodriguez: 03 09 1981
Carlos Chato: 01 05 1965
Lyric Thomas: 04 23 1996
Imogen Thompson: 10 20 1986
Bridget Mcleary: 07 06 2003
Jackson Brigger: 05 24 1993
Mason Dean: 05 11 1994
Jane Jumper: 09 01 1938
Roger Dhat: 01 17 1997
Mary Molina: 06 06 1994
Margret Mercener: 04 17 1983
Elliot Boyd: 03 29 1989
Richard Clinton: 08 05 1954
James Johnson: 10 13 2005
Chris Camp: 07 20 1989
Diana Boteo : 05 18 1993
Leana Bryn: 02 23 1990
Melissa Hatcher: 06 02 2000
Terri Trang: 01 30 1973
Trixie Parker: 08 14 1943
Kianna Marin: 03 01 1990
Darren Richards: 09 07 1980
Peter Matthews: 02 01 1986
Lebron James: 03 15 1974
Stephen Curry: 02 18 1983
Ayesha Curry: 07 10 1949
Damian Moss: 01 12 2004
Dominique Ross: 06 01 1999
Matthew Harper: 02 16 2001
Jean Dean: 03 19 1997
Billy Bob: 08 17 1990
Harold Churchill: 10 24 1996
Younes Azim: 11 03 1991
Evan Green: 12 20 1972
Markus Matthers: 12 31 1995
Parker Hollins: 04 01 2007
Amelia Shart: 01 13 1998
Karen Jackson: 11 19 1929
Phillip Limbert: 03 18 1992
Harrison LeValley: 02 14 1964
Isaac Jermaine:01 03 1999
Chris Griffin: 12 02 2009
Megan Roberts: 03 05 1984
Fiona Bean: 11 04 1994
Nicole Poff: 10 21 2003
Christine Harlow: 01 14 1991
Randall Pearson: 10 23 1993
Kyle Griffith: 09 12 1937
Sue Arbor: 02 01 1933
Jesse James:05 02 1997
Michael Patrick: 06 23 1987
Dean Drapper: 03 27 1936
Peggy Holt: 10 21 1974
Elizabeth Bryant:10 06 1972
Oliver Rimmer: 09 03 1928
Ruth Dash: 08 18 1992
Aaron Paul: 08 27 1979
Emilia Peters: 03 19 1920
Jason Brown: 07 04 1994
Julia Jordan: 02 09 1972
Sarah Porter: 05 11 1991
Pete Ross: 10 02 1944
Jimmy Campbell: 04 15 1924
Sophia Gomez: 10 17 1992
Genesis Ruiz: 08 03 1997
Mina Khan: 05 27 1997
Laura Kelly: 06 11 1967
Olivia Hart: 04 17 1993
Tristian Gains: 09 15 1990
Liam Hern: 03 02 2007
Kia Lyser: 01 18 1993
Diana Portillo: 02 28 1955
Jeremy Daniels: 05 13 1995
Brian Parker: 07 04 1982
Steve Nelson: 02 18 1984
Harvey Olson: 07 19 1958
Don Portillo: 09 11 1957
Jennifer Benitez: 04 27 1990
Donna Zander: 07 02 1975
Henry Nun: 04 04 2005
Jeffery Brit: 07 09 2009
Thomas Earns: 01 10 2008
Chloe Michaels : 05 29 1983
Kelly Roberts: 05 05 1995
Joseph Rivas : 04 05 1982
Wren Choi: 01 02 2001
Lana Guzman: 03 02 2003
Daniel Krause: 07 20 1991
Kevin Han: 09 14 1992
Dylan Rogers: 03 09 1982
Daphne Klein 01 09 1997
Explanation / Answer
Code:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.StringTokenizer;
public class BirthdayMatch {
public static void main(String args[]) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(new File("BirthDay.txt"));
String[] birthDay = new String[100];
int count = 0;
while (scan.hasNext()) {
String text = scan.nextLine();
if (text.trim().length() > 0) {
birthDay[count++] = text;
}
}
Scanner scanInp = new Scanner(System.in);
String option = "";
do {
System.out.print("Enter DOB(in MM DD YYYY) to search: ");
String dob = scanInp.nextLine();
boolean match = false;
for (String s : birthDay) {
if (s.contains(dob)) {
StringTokenizer st = new StringTokenizer(s, " ");
String name = st.nextToken() + " " + st.nextToken();
System.out.println("Match Found and its " + name);
match = true;
break;
}
}
if(!match)
System.out.println("No match found");
System.out.print("Do you want to search more? Y/N: ");
option = scanInp.nextLine().charAt(0) + "";
} while (option.equalsIgnoreCase("Y"));
}
}
Output
Enter DOB(in MM DD YYYY) to search: 09 17 1991
Match Found and its Michael Murray:
Do you want to search more? Y/N: Y
Enter DOB(in MM DD YYYY) to search: 07 31 1980
Match Found and its Harry Potter:
Do you want to search more? Y/N: N
Enter DOB(in MM DD YYYY) to search: 12 12 2017
No match found
Do you want to search more? Y/N: N
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.