You will a program that reads a file that ranks the populari
You will a program that reads a file that ranks the popularity of names in the year 2000. You will then let the user get statistics by name and by ranking. Below is a sample run of the program (user input is bolded):
Input File
https://k-state.instructure.com/courses/24972/files/2960472/download?download_frd=1
Is the link that contains the ranking information for a collection of names in the year 2000.
The first line is the number of names in the file. The second line is blank. The rest of the file (4408 lines, as the first line indicates) is the ranking information for each name. For “Aaron” above, this means that Aaron was the 41st most common boy’s name in 2000. If a name lists “0” as its rank, that means that it was not ranked within the top 1000 names in the year 2000.
You will want to save the names.txt file in the proj6 folder that BlueJ creates for your project.
Requirements
Please make it go along with this code outline:
/**
 * Project 6 finds various statistics about name popularity
 *
 * @author Julie Thornton
 * @version Project 6
 */
import java.io.*;
 import java.util.*;
public class Proj6 {
 private static String[] names;
 private static int[] rankings;
 private static Scanner s;
public static void main(String[] args) throws IOException {
 //THIS METHOD IS FINISHED -- DON\'T CHANGE IT!
s = new Scanner(System.in);
 System.out.print(\"Enter name of file: \");
 String filename = s.nextLine();
readNamesData(filename);
 controlLoop();
 }
/**
 * readNamesData reads a file of name statistics and stores the data
 *
 * @param filename The filename
 */
 public static void readNamesData(String filename) throws IOException {
 //THIS METHOD IS FINISHED -- DON\'T CHANGE IT!
Scanner inFile = new Scanner(new File(filename));
 int size = Integer.parseInt(inFile.nextLine());
 inFile.nextLine();
names = new String[size];
 rankings = new int[size];
for (int i = 0; i < size; i++) {
 String line = inFile.nextLine();
 String[] pieces = line.split(\" \");
 names[i] = pieces[0];
 rankings[i] = Integer.parseInt(pieces[1]);
 }
inFile.close();
 }
/**
 * controlLoop repeatedly lets the user search by name, ranking,
 * or quit the program
 */
 public static void controlLoop() {
 while (true) {
            //YOU DO THIS:
            //Ask the user to enter an option (n, r, q)
            //If the user enters n
                //Get the name from the user and call searchName
           //If the user enters r
                //Get the rank from the user
                //Check that the rank is in the 1-1000 range
                //If so, call searchRanking
           //If the user enters q
                return; //(this leaves the controlLoop) }
 }
 }
/**
 * nameIndex gets the index of name within the names array
 *
 * @param name The name to find
 * @return The index of name in the names array
 */
 public static int nameIndex(String name) {
        //YOU DO THIS:
        //Loop through the names array with a for loop (use i to count)
            //If the current name in the array equals the name parameter, return i
       //LEAVE THE LINE BELOW ALONE
 return -1; //(-1 will be returned if the name isn\'t in the array)
 }
/**
 * searchName prints the ranking for the given name.
 *
 * @param name The name to print statistics for
 */
 public static void searchName(String name) {
        //YOU DO THIS:
       //Call nameIndex to get the index of name in your names array
        //If the index is -1, print an error
        //Otherwise
            //get the rank at that index in the ranking array
            //If the rank is 0, this means the name is not ranked in the top 1000
            //Otherwise, print the ranking of the name
 }
/**
 * rankIndex gets the two index of rank within the rankings array
 *
 * @param rank The rank to find
 * @return The array of the two indices of rank in the rankings array
 */
 public static int[] rankIndex(int rank) {
 //THIS METHOD IS COMPLETE -- DON\'T CHANGE IT!
int[] spots = new int[2];
int pos = 0;
 for (int i = 0; i < rankings.length; i++) {
 if (rankings[i] == rank) {
 spots[pos] = i;
 pos++;
 }
 }
return spots;
 }
/**
 * searchRanking prints the names with the given ranking
 *
 * @param rank The rank to search for
 */
 public static void searchRanking(int rank) {
 //LEAVE THE LINE BELOW ALONE
 int[] indices = rankIndex(rank);
       //YOU DO THIS:
        //indices is an array with two elements. The first position is the
        //index of the first name with that ranking, and the second position is the
        //index of the second name with that ranking.
       //Look up those two indices in your names array, and print the names
 }
 }
Additional requirements:
You should accept upper- or lower-case input for the command options (n, r, and q). If the user enters a different letter, you should print an error and prompt again for input.
You may assume that users will search for names using the same capitalization as in the names file (capital first letter and the rest lower-case, like “Robin”)
You should print an error if the user searches for a name that was not in the file
You should print an error if the user searches for a ranking that is not in the range 1-1000.
When searching by ranking, there will be TWO names with the given rank (a boy’s name and a girl’s name). You should print them both.
When searching by name, if the file had a “0” as the ranking, you should print that the name was not ranked in the top 1000. Do not print 0 as the ranking.
You should store the names and the rankings from the file in two arrays.
Design Requirements
Solution
import java.io.*;
 import java.util.*;
 public class Proj6 {
 private static String[] names;
 private static int[] rankings;
 private static Scanner s;
 public static void main(String[] args) throws IOException {
 //THIS METHOD IS FINISHED -- DON\'T CHANGE IT!
 s = new Scanner(System.in);
 System.out.print(\"Enter name of file: \");
 String filename = s.nextLine();
 readNamesData(filename);
 controlLoop();
 }
 
 public static void readNamesData(String filename) throws IOException {
 //THIS METHOD IS FINISHED -- DON\'T CHANGE IT!
 Scanner inFile = new Scanner(new File(filename));
 int size = Integer.parseInt(inFile.nextLine());
 inFile.nextLine();
 names = new String[size];
 rankings = new int[size];
 for (int i = 0; i < size; i++) {
 String line = inFile.nextLine();
 String[] pieces = line.split(\" \");
 names[i] = pieces[0];
 rankings[i] = Integer.parseInt(pieces[1]);
 }
 inFile.close();
 }
 
 public static void controlLoop() {
 while (true) {
   
        System.out.println(\"to Search by name enter n, by ranking enter r, or to quit enter q ? \");
        Scanner option=new Scanner(System.in);
   
        if(option.equalsIgnoreCase( \"n\" ){
            System.out.println(\"enter name? \");
            Scanner namei=new Scanner(System.in);
           
                searchName(namei)=new searchName(namei);
        }
 if(option.equalsIgnoreCase( \"r\" ){
 System.out.println(\"enter rank? \");
            Scanner rank=new Scanner(System.in);
 if(1<rank<1001){
 searchRanking(rank)=new searchRankin(rank);
}
 else{
 System.out.println(\'rank is not in the list\");
 }
 }
           
 if(option.equalsIgnoreCase( \"q\" ){      
   
   
 return;
 }
 }
 }
 /**
 * nameIndex gets the index of name within the names array
 *
 * @param name The name to find
 * @return The index of name in the names array
 */
 public static int nameIndex(String name) {
 for (int i = 0; i < size; i++) {
 int nameIndex = names.indexOf(\"Hello\");
        if(nameIndex==-1){
        return -1; }
        else{
       return i;
             }
            }
   
 }
 /**
 * searchName prints the ranking for the given name.
 *
 * @param name The name to print statistics for
 */
 public static void searchName(String name) {
 //YOU DO THIS:
        if(intIndex == - 1){
 System.out.println(\"name not found\");
 }else{
 nameIndex(String name)=new nameIndex(namei);
    rankIndex(int rank)=new rankIndex(i);
 if(spots==0){
 System.out.println(\"name is not in the list\");
}
    else{
 searchRanking(int rank)= new searchRanking(spots);
 System.out.println(\"\"+spots);
    }
   
 
 }
 
 public static int[] rankIndex(int rank) {
 //THIS METHOD IS COMPLETE -- DON\'T CHANGE IT!
 int[] spots = new int[2];
 int pos = 0;
 for (int i = 0; i < rankings.length; i++) {
 if (rankings[i] == rank) {
 spots[pos] = i;
 pos++;
 }
 }
 return spots;
 }
   
 public static void searchRanking(int rank) {
 
   
   
    int[] indices = rankIndex(rank);
 rankIndex(String name)=new rankIndex(namei);
   
   
   
 }
 }





