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

[Java] Please test your code in the link I provide before you post your answer.

ID: 3824214 • Letter: #

Question

[Java] Please test your code in the link I provide before you post your answer.

The output should be looked like exact same as the tester.

http://www.codecheck.it/files/17010904417sjt8pfrszn19003sdj8aylke

If your answer can't pass the tester, I have to down-thumb your answer.

Thank you

The United States Social Security Administration keeps lists of the most popular baby names by year and by decade. We have two list:, one from the 1900 to 1909 and one 100 years later from the 2000 to 2009. Each contains the top names for the decade. We want to know what names from the 1900s were still popular in the 2000s.

Write an application called BabyNames1900sAnd2000s to print two columns in alphabetical order. The first column will contain all the boys names for 1900s that were still popular in 2000s. The second column will contain all the girls names for 1900s that were still popular in 2000s. Make the columns 30 characters wide and left justified.

You can get the files from the following URLs

http://www.laughton.com/obrien/sjsu/cs49j/spring17/files/babynames1900s.txt

http://www.laughton.com/obrien/sjsu/cs49j/spring17/files/babynames2000s.txt

Here is the file format

Do not use try / catch here. Just declare that the method throws an exception

For full points, design the program so you only read each file one time.

Explanation / Answer

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class BabyNames1900sAnd2000s {
   private static final String FILENAME = "C:/Users/anmamaha/Desktop/records.txt";
   public static void main(String args[]) throws IOException{
       BufferedReader br = null;
       FileReader fr = null;
      
       Set<String> boysSet = new TreeSet<String>();
       Set<String> girlsSet = new TreeSet<String>();
       fr = new FileReader(FILENAME);
       br = new BufferedReader(fr);

       String sCurrentLine;

       br = new BufferedReader(new FileReader(FILENAME));
       int i=0;
       while ((sCurrentLine = br.readLine()) != null) {
           if(i!=0)
           {
               String line[] = sCurrentLine.split(" ");
               boysSet.add(line[1]);
               girlsSet.add(line[3]);
           }
           i++;
       }

       System.out.print("Boys list is: ");
       Iterator itr = boysSet.iterator();
       while(itr.hasNext())
           System.out.print(itr.next()+" ");
       System.out.println();
       System.out.print("Girls list is: ");
       itr = girlsSet.iterator();
       while(itr.hasNext())
           System.out.print(itr.next()+" ");
}

}

please find the content of the file records.txt

Rank Name Number Name Number
1 John 84,591 Mary 161,508
2 William 69,321 Helen 69,429
3 James 62,170 Margaret 57,921
4 George 43,589 Anna 54,918
5 Charles 36,186 Ruth 51,011

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote