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

Using the Design Recipe and Netbeans, write a Java program that: 1- creates four

ID: 3765996 • Letter: U

Question

Using the Design Recipe and Netbeans, write a Java program that:

1- creates four arrays (or ArrayLists) that store:

i- a list of boy names (e.g., called boyNames)

ii- the corresponding list of popularity rankings, one per boy name (e.g., called boyPopularities)

iii- a list of girl names (e.g., called girlNames)

iiii- the corresponding list of popularity rankings, one per girl names (e.g., called girlPopularities)

2- reads the boy names and popularities from the text file boynames.txt into the boyNames and boyPopularities arrays
Note that there are 1,000 boy names, and the format of each line of the boynames.txt file is:

    Jacob 29195

3- reads the girl names and popularities from the text file girlnames.txt into the girlNames and girlPopularities arrays
Note that there are 1,000 girl names, and the format of each line of the girlNames.txt file is:

    Emily 25494

4- using a loop, continuously presents the user with a prompt to enter a name, until the user enters "quit". Each time the user enters a name:

i- show the popularity of that name among the list of boy names; if the name is not in the list, show a "not found" message

ii- show the popularity of that name among the list of girl names; if the name is not in the list, show a "not found" message

Sample Run (user input in color):

Enter a name: Jacob
The popularity of "Jacob" among boy names is 29195.
The name "Jacob" was not found among girl names.

Enter another name (or "quit"): Emma
The name "Emma" was not found among boy names.
The popularity of "Emma" among girl names is 22532.

Enter another name (or "quit"): Alexis
The popularity of "Alexis" among boy names is 2805.
The popularity of "Alexis" among girl names is 14659.

Enter another name (or "quit"): Fran
The name "Fran" was not found among boy names.
The name "Fran" was not found among girl names.

Enter another name (or "quit"): quit

Explanation / Answer

Program

import java.util.Scanner;

import java.io.*;

import java.io.File;

        

public class Print{

     public static void main(String[] args)

     {

          int[] studentId = new int[1000];

          String[] studentName= new String[1000];

          int[] studentId1 = new int[1000];

          String[] studentName1= new String[1000];

         

          int flag1=0, flag2=0;

          Scanner in = new Scanner(System.in);

          String girls = "girls.txt";

          String boys="boys.txt";

          try {

FileReader fileReader = new FileReader(boys);

BufferedReader bufferedReader = new BufferedReader(fileReader);

                   String line1;

                   int Index = 0;

                   String[] lineSplit;

                       

while ((line1 = bufferedReader.readLine())=null)

                   {

                        //System.out.println(line);

                        lineSplit = line1.split(" ");

                       

                        studentName[Index] = lineSplit[0];

                       

              studentId[Index] =

Integer.parseInt(lineSplit[1]);

                        Index++;

                   }

                   FileReader fileReader1 = new

FileReader(girls);

                   BufferedReader bufferedReader1 = new

BufferedReader(fileReader1);

                   String line2;

                   int Index1 = 0;

                   String[] lineSplit1;

                   while ((line2 = bufferedReader1.readLine())

!= null)

                   {

                        //System.out.println(line);

                        lineSplit1= line2.split(" ");

                        studentName1[Index1] = lineSplit1[0];

                        studentId1[Index1] =

Integer.parseInt(lineSplit1[1]);

                        Index1++;

                   }

                   String name1;

                   System.out.println("Enter the name :");

                   String name=in.nextLine();

                   for(int i=0;i<Index;i++)

                   {

                        if(name.equals(studentName[i]))

                        {

                             System.out.println("The pouplarity

of " + name + " among boy names was found to be " + studentId[i]);

                             flag1=1;

                        }   

                        if(name.equals(studentName1[i]))

                        {

                             System.out.println("The pouplarity

of " + name + " among girl name was found to be " + studentId1[i]);

                             flag2=1;

                        }

                   }

                   if((flag2==1 )&& (flag1==0))

                   {

                        System.out.println("The name " +name+ "

was not found among boys names.");

                   }

                   else if((flag1==1) && (flag2==0))

                   {

                        System.out.println("The name " +name+ "

was not found among girls names.");

                   }

                       

          } catch (IOException ex) {

                             System.out.println("error");

          }

     }

}

Result :

Enter the name :
Alexis
The pouplarity of Alexis among boy names was found to be 2805
The pouplarity of Alexis among girl name was found to be 14659

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