Introduction to Java Programming Brief Version 10th Edition 12.31 question The p
ID: 3763598 • Letter: I
Question
Introduction to Java Programming Brief Version 10th Edition
12.31 question
The popularity ranking of baby names from years 2001 to 2010 is downloaded from Each file contains one thousand lines. Each line contains a ranking, a boy's name, number for the boy's name, a girl's name, and number for the girl's name. For example, the first two lines in the file babynameranking2010.txt are as follows: So, the boy's name Jacob and girl's name Isabella are ranked #1 and the boy's name Ethan and girl's name Sophia are ranked #2. 21,875 boys are named Jacob and 22,731 girls are named Isabella. Write a program that prompts the user to enter the year, gender, and followed by a name, and displays the ranking of the name for the year. Here is a sample run:Explanation / Answer
import java.io.*;
import java.util.*;
public class BabyNames
{
public static void main(String[] args)
throws FileNotFoundException
{
System.out.println("Popularity of a baby name since year 2010 ");
Scanner input = new Scanner(new File("names.txt"));
Scanner console = new Scanner(System.in);
System.out.print("please enter the name ");
String chosenOne = console.nextLine();
do
{
PrintStream out = new PrintStream(new File(chosenOne + ".txt"));
out.println(chosenOne + ",");
howPopular(chosenOne, out, input);
}
while (input.hasNextLine());
System.out.println("Sorry requested name not found.");
}
public static void howPopular(String chosenOne, PrintStream out, Scanner input)
{
if (input.hasNextLine())
{
String theName = input.nextLine();
Scanner linescan = new Scanner(theName);
String line = linescan.next();
line.toString();
int x = -1;
while (line.equalsIgnoreCase(chosenOne) && x <= 7)
{
int popular = linescan.nextInt();
x++;
int year = 2010+ (10 * x);
System.out.println(year + ": " + popular);
if (x <= 7)
{
out.println(year + ": " + popular + ", ");
}
else if (x <= 8)
{
out.println(2080 + ": " + popular);
}
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.