Problem Description: In JAVA
The popularity ranking of baby names are provided every year by the Social Security Administration. Write a program that reads from the keyboard the ranking list. Each line contains a ranking, a boy’ name, and a girl’s name (ends with 0). For example, the first two lines are as follows:
1 Liam Emma
2 Noah Olivia
So, the boy’s name Liam and girl’s name Emma are ranked #1 and the boy’s name Noah and girl’s name Olivia are ranked #2. The program then reads from the keyboard the gender (‘M’ for boys and ‘F’ for girls) followed by a name, and displays the ranking of the name. Input ends with an ‘E’. If a name is not on the list, the ranking is -1. Run and make sure that your program produces exactly the same output for each of the sample inputs
listed below.
Sample Input 1:
1 Liam Emma
2 Noah Olivia
21 Samuel Grace
22 Sebastian Chloe
23 David Camila
24 Carter Penelope
25 Wyatt Riley
29 Dylan Zoey
30 Luke Mila
31 Gabriel Aubrey
32 Anthony Hannah
135 Ivan Arya
136 Maddox Norah
137 Juan Khloe
138 Ashton Kayla
139 Jayce Eden
0
M Luke
F Mila
F Jackson
F Chloe
M Ashton
M Isla
E
Sample Output 1:
30
30
-1
22
138
-1
Sample Input 2:
163 Xander Jocelyn
164 Timothy Kimberly
165 Victor Esther
166 Bryce Molly
171 Patrick Reese
172 Grant Laila
173 Karter Mya
174 Hayden Amy
175 Richard Teagan
248 Jake Jessica
249 Killian Remi
250 Clayton Delaney
251 Sean Camille
807 Emory Scarlette
808 Skylar Belle
809 Sutton Lea
810 Alfonso Nalani
811 Brentley Rivka
812 Toby Ayleen
813 Blaze Calliope
814 Eugene Dalary
815 Shiloh Zaniyah
0
F Iker
M Hayden
M Xander
F Jessica
M Emory
F Zaniyah
E
Sample Output 2:
-1
174
163
248
807
815
Sample Input 3:
695 Lachlan Chaya
696 Layne Frida
697 Clay Bonnie
698 Madden Amora
699 Jamir Stevie
890 Draven India
891 Xzavier Janessa
892 Darrell Paloma
893 Keanu Ramona
894 Ronnie Sandra
895 Konnor Abril
945 Vivaan Legacy
946 Brayson Marjorie
947 Emmet Paityn
948 Marley Courtney
949 Mike Ellianna
950 Nickolas Jurnee
951 Kenny Karlie
0
M Emmet
F Frida
F Denver
F Paloma
M Texas
F Louisiana
E
Sample Output 3:
947
696
-1
892
-1
-1
import java.util.*;
import java.util.ArrayList;
//class Ranking
class Ranking
{
//main method
public static void main (String[] args)
{
//declare ArrayLists
ArrayList <Integer>rank = new
ArrayList<>();
ArrayList <String>boys = new
ArrayList<>();
ArrayList <String>girls = new
ArrayList<>();
//create an instance of Scanner
class
Scanner sc = new
Scanner(System.in);
//while loop
while(true)
{
//read
rank
int r =
sc.nextInt();
//check if
zero
if(r==0)
break;
//add to the
ArrayList
rank.add(r);
//read boy's
name
String boy =
sc.next();
//add to the
ArrayList
boys.add(boy);
//read girl's
name
String girl =
sc.next();
//add to the
ArrayList
girls.add(girl);
}
//declare ArrayLists
ArrayList <Character>genders
= new ArrayList<>();
ArrayList <String>names = new
ArrayList<>();
//while loop
while(true)
{
//read
gender
char gender =
sc.next().charAt(0);
//check if
'E'
if(gender=='E')
break;
//add to the
ArrayList
genders.add(gender);
//read the
name
String name =
sc.next();
//add to the
ArrayList
names.add(name);
}
//for loop
for(int i=0; i<names.size();
i++)
{
//get gender and
name from ArrayList
char gender =
genders.get(i);
String name =
names.get(i);
int pos;
//check if
gender 'M'
if(gender=='M')
pos = boys.indexOf(name);
else
pos = girls.indexOf(name);
//check if -1
otherwist print the rank
if(pos==-1)
System.out.println("-1");
else
System.out.println(rank.get(pos));
}
}
}
Output 1:
Output 2:
163 Xander Jocelyn
164 Timothy Kimberly
165 Victor Esther
166 Bryce Molly
171 Patrick Reese
172 Grant Laila
173 Karter Mya
174 Hayden Amy
175 Richard Teagan
248 Jake Jessica
249 Killian Remi
250 Clayton Delaney
251 Sean Camille
807 Emory Scarlette
808 Skylar Belle
809 Sutton Lea
810 Alfonso Nalani
811 Brentley Rivka
812 Toby Ayleen
813 Blaze Calliope
814 Eugene Dalary
815 Shiloh Zaniyah
0
F Iker
M Hayden
M Xander
F Jessica
M Emory
F Zaniyah
E
-1
174
163
248
807
815
Output 3:
695 Lachlan Chaya
696 Layne Frida
697 Clay Bonnie
698 Madden Amora
699 Jamir Stevie
890 Draven India
891 Xzavier Janessa
892 Darrell Paloma
893 Keanu Ramona
894 Ronnie Sandra
895 Konnor Abril
945 Vivaan Legacy
946 Brayson Marjorie
947 Emmet Paityn
948 Marley Courtney
949 Mike Ellianna
950 Nickolas Jurnee
951 Kenny Karlie
0
M Emmet
F Frida
F Denver
F Paloma
M Texas
F Louisiana
E
947
696
-1
892
-1
-1
N.B Whether you face any problem then share with me in the comment section, I'll happy to help you. I expect positive feedback from your end.
1 Liam Emma 2 Noah Olivia 21 Samuel Grace 22 Sebastian Chloe 23 David Camila 24 Carter Penelope 25 Wyatt Riley 29 Dylan Zoey 30 Luke Mila 31 Gabriel Aubrey 32 Anthony Hannah 135 Ivan Arya 136 Maddox Norah 137 Juan Khloe 138 Ashton Kayla 139 Jayce Eden M Luke F Mila F Jackson F Chloe MAshton M Isla 30
Problem Description: In JAVA The popularity ranking of baby names are provided every year by the...
C++ Create an application that searches a file of male and female first names. A link to the file is provided on the class webpage. "FirstNames2015.txt" is a list of the most popular baby names in the United States and was provided by the Social Security Administration. Each line in the file contains a boy's name and a girl's name. The file is space-delimited, meaning that the space character is used to separate the boy name from the girl name....