In: Computer Science
PLEASE DO IN JAVA AND USING REPL.IT
Below are the two files, boysNames.txt and GirlsNames.txt
Write a program that reads the contents of the two files into two separate arrays, or ArrayLists. The user should be able to enter a boy’s name, a girl’s name, or both, and the application will display messages indicating whether the names were among the most popular.
BoyNames:
Jacob
Michael
Joshua
Matthew
Daniel
Christopher
Andrew
Ethan
Joseph
William
Anthony
David
Alexander
Nicholas
Ryan
Tyler
James
John
Jonathan
Noah
Brandon
Christian
Dylan
Samuel
Benjamin
Zachary
Nathan
Logan
Justin
Gabriel
Jose
Austin
Kevin
Elijah
Caleb
Robert
Thomas
Jordan
Cameron
Jack
Hunter
Jackson
Angel
Isaiah
Evan
Isaac
Mason
Luke
Jason
Gavin
Jayden
Aaron
Connor
Aiden
Aidan
Kyle
Juan
Charles
Luis
Adam
Lucas
Brian
Eric
Adrian
Nathaniel
Sean
Alex
Carlos
Bryan
Ian
Owen
Jesus
Landon
Julian
Chase
Cole
Diego
Jeremiah
Steven
Sebastian
Xavier
Timothy
Carter
Wyatt
Brayden
Blake
Hayden
Devin
Cody
Richard
Seth
Dominic
Jaden
Antonio
Miguel
Liam
Patrick
Carson
Jesse
Tristan
Alejandro
Henry
Victor
Trevor
Bryce
Jake
Riley
Colin
Jared
Jeremy
Mark
Caden
Garrett
Parker
Marcus
Vincent
Kaleb
Kaden
Brady
Colton
Kenneth
Joel
Oscar
Josiah
Jorge
Cooper
Ashton
Tanner
Eduardo
Paul
Edward
Ivan
Preston
Maxwell
Alan
Levi
Stephen
Grant
Nicolas
Omar
Dakota
Alexis
George
Collin
Eli
Spencer
Gage
Max
Cristian
Ricardo
Derek
Micah
Brody
Francisco
Nolan
Ayden
Dalton
Shane
Peter
Damian
Jeffrey
Brendan
Travis
Fernando
Peyton
Conner
Andres
Javier
Giovanni
Shawn
Braden
Jonah
Cesar
Bradley
Emmanuel
Manuel
Edgar
Erik
Mario
Edwin
Johnathan
Devon
Erick
Wesley
Oliver
Trenton
Hector
Malachi
Jalen
Raymond
Gregory
Abraham
Elias
Leonardo
Sergio
Donovan
Colby
Marco
Bryson
Martin
GirlsNames:
Emily
Madison
Emma
Olivia
Hannah
Abigail
Isabella
Samantha
Elizabeth
Ashley
Alexis
Sarah
Sophia
Alyssa
Grace
Ava
Taylor
Brianna
Lauren
Chloe
Natalie
Kayla
Jessica
Anna
Victoria
Mia
Hailey
Sydney
Jasmine
Julia
Morgan
Destiny
Rachel
Ella
Kaitlyn
Megan
Katherine
Savannah
Jennifer
Alexandra
Allison
Haley
Maria
Kaylee
Lily
Makayla
Brooke
Mackenzie
Nicole
Addison
Stephanie
Lillian
Andrea
Zoe
Faith
Kimberly
Madeline
Alexa
Katelyn
Gabriella
Gabrielle
Trinity
Amanda
Kylie
Mary
Paige
Riley
Jenna
Leah
Sara
Rebecca
Michelle
Sofia
Vanessa
Jordan
Angelina
Caroline
Avery
Audrey
Evelyn
Maya
Claire
Autumn
Jocelyn
Ariana
Nevaeh
Arianna
Jada
Bailey
Brooklyn
Aaliyah
Amber
Isabel
Danielle
Mariah
Melanie
Sierra
Erin
Molly
Amelia
Isabelle
Madelyn
Melissa
Jacqueline
Marissa
Shelby
Angela
Leslie
Katie
Jade
Catherine
Diana
Aubrey
Mya
Amy
Briana
Sophie
Gabriela
Breanna
Gianna
Kennedy
Gracie
Peyton
Adriana
Christina
Courtney
Daniela
Kathryn
Lydia
Valeria
Layla
Alexandria
Natalia
Angel
Laura
Charlotte
Margaret
Cheyenne
Mikayla
Miranda
Naomi
Kelsey
Payton
Ana
Alicia
Jillian
Daisy
Mckenzie
Ashlyn
Caitlin
Sabrina
Summer
Ruby
Rylee
Valerie
Skylar
Lindsey
Kelly
Genesis
Zoey
Eva
Sadie
Alexia
Cassidy
Kylee
Kendall
Jordyn
Kate
Jayla
Karen
Tiffany
Cassandra
Juliana
Reagan
Caitlyn
Giselle
Serenity
Alondra
Lucy
Kiara
Bianca
Crystal
Erica
Angelica
Hope
Chelsea
Alana
Liliana
Brittany
Camila
Makenzie
Veronica
Lilly
Abby
Jazmin
Adrianna
Karina
Delaney
Ellie
Jasmin
Please find the answer below:-
Code for displaying File content :-
Output:-
Code for finding names in the FIle:
Output 1:-
Output 2:
Thanks.
Hope you like the answer.
Code for displaying File content :-
package FileReadDemo;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.FileReader;
class Main {
public static void main(String[] args) throws IOException {
System.out.println("Hello world!");
ArrayList<String> boysNames = new
ArrayList<String>();
ArrayList<String> girlsNames = new
ArrayList<String>();
// Since file has dynamic size data, so consider ArrayList.
File boysFileName = new
File("boysNames.txt");
File girlsFileName = new File("GirlsNames.txt");
FileReader frBoys = new
FileReader(boysFileName);
FileReader frGirls = new FileReader(girlsFileName);
BufferedReader brBoys = new
BufferedReader(frBoys);
BufferedReader brGirls = new BufferedReader(frGirls);
// used for reading the file
while (brBoys.ready()) { // loop
will break at EOL(End Of Line)
boysNames.add(brBoys.readLine()); // Adding file contents to an
ArrayList.
}
System.out.println("BoyNames");
for(String b:boysNames){
System.out.println(b);
}
while (brGirls.ready()) { // loop will break at EOL(End Of
Line)
girlsNames.add(brGirls.readLine()); // Adding file contents to an
ArrayList.
}
System.out.println("GirlNames");
for(String g:girlsNames){
System.out.println(g);
}
}
}
Code for finding names in the FIle:
import java.util.ArrayList;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.FileReader;
class Main {
public static void main(String[] args) throws IOException {
System.out.println("Hello world!");
String inputName;
ArrayList<String> boysNames = new ArrayList<String>();
ArrayList<String> girlsNames = new ArrayList<String>();
List userInputName = new ArrayList<String>();
// Since file has dynamic size data, so consider ArrayList.
File boysFileName = new File("boysNames.txt");
File girlsFileName = new File("GirlsNames.txt");
FileReader frBoys = new FileReader(boysFileName);
FileReader frGirls = new FileReader(girlsFileName);
BufferedReader brBoys = new BufferedReader(frBoys);
BufferedReader brGirls = new BufferedReader(frGirls);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// used for reading the file
while (brBoys.ready()) { // loop will break at EOL(End Of Line)
boysNames.add(brBoys.readLine()); // Adding file contents to an ArrayList.
}
System.out.println("Enter a Boy name or Girl name or both: ");
inputName = br.readLine();
String str[] = inputName.split(" ");
userInputName = Arrays.asList(str);
for(String b:boysNames){
for(int i=0;i<userInputName.size();i++){
if(((String)userInputName.get(i)).equalsIgnoreCase(b)){
System.out.println("Boy Name is present: ");
System.out.println(b);
}
}
}
while (brGirls.ready()) {
// loop will break at EOL(End Of Line)
girlsNames.add(brGirls.readLine()); // Adding file contents to an ArrayList.
}
for(String g:girlsNames){
for(int i=0;i<userInputName.size();i++){
if(((String)userInputName.get(i)).equalsIgnoreCase(g)){
System.out.println("Girl Name is present: ");
System.out.println(g);
}
}
}
}
}
Thanks.
Hope you like the answer.