The web sites http://www.census.gov/genealogy/names/dist.male.first and http://www.census.gov/genealogy/names/dist.female.first contain baby names sorted by popularity. The format is very simple: name, frequency, cumulative frequency, and rank. Load these pages into your browser to see for yourself.

Your task is to write a program that connects to these sites and prints the top 50% of male and female names. Stop when the cumulative percentage has exceeded 50%.

Complete the following file:

PopularNames.java

import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.util.Scanner; public class PopularNames { public static void main(String[] args) throws IOException { System.out.println("Male:"); printPopularNames("http://www.census.gov/genealogy/names/dist.male.first"); System.out.println("Female:"); printPopularNames("http://www.census.gov/genealogy/names/dist.female.first"); } public static void printPopularNames(String urlString) throws IOException { // Connect to server // Check if response code is HTTP_OK (200) // Read server response while (. . .) { // Read one record // Print rank and name } } }