Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Name Search BoyNames.txt: https://atlanticbb9.blackboard.com/bbcswebdav/pid-6731

ID: 3579186 • Letter: N

Question

Name Search

BoyNames.txt: https://atlanticbb9.blackboard.com/bbcswebdav/pid-673166-dt-content-rid-2269978_1/courses/CISM154DICKER_2016FA/BoyNames.txt

GirlNames.txt: https://atlanticbb9.blackboard.com/bbcswebdav/pid-673166-dt-content-rid-2269979_1/courses/CISM154DICKER_2016FA/GirlNames.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.

Java Early Objects 5th Edition

Programming Challenge 13

Pg. 543

Explanation / Answer

import java.util.*;
import java.io.*;

class Main {
public static void main(String args[])throws Exception{
  
FileInputStream boyfstream = new FileInputStream("Boys.txt");
BufferedReader br1 = new BufferedReader(new InputStreamReader(boyfstream));
FileInputStream girlfstream = new FileInputStream("Girls.txt");
BufferedReader br2 = new BufferedReader(new InputStreamReader(girlfstream));
Scanner inp = new Scanner(System.in);
String[] bnames;
String[] gnames;
String strLineboy;
String strLinegirl;
  
List<String> blist = new ArrayList<String>();
while ((strLineboy = br1.readLine()) != null){
blist.add(strLineboy);
}
String[] barr = blist.toArray(new String[0]);
  
List<String> glist = new ArrayList<String>();
while ((strLinegirl = br2.readLine()) != null){
blist.add(strLinegirl);
}
String[] garr = glist.toArray(new String[0]);
  
String BoyName;
BoyName = "";
System.out.print("Please enter the Boy name:");
BoyName = inp.nextLine();
  
String GirlName;
GirlName = "";
System.out.print("Please enter the Girl name:");
GirlName = inp.nextLine();
  
if(!BoyName.isEmpty()){
for(int i=0;i<barr.length;i++){
if(BoyName.equal(barr[i])){
System.out.println("Boy name '"+ BoyName + "' is among the most popular");
}else{
System.out.println("Boy name '"+ BoyName + "' is not among the most popular");
}
}
}
  
  
if(!GirlName.isEmpty()){
for(int i=0;i<barr.length;i++){
if(GirlName.equal(barr[i])){
System.out.println("Girl name '"+ GirlName + "' is among the most popular");
}else{
System.out.println("Girl name '"+ GirlName + "' is not among the most popular");
}
}
}
  
  
br1.close();
br2.close();
}
}