I am having problems with this line of code:
--System.out.println(line +"is ranked at" + location + " in popularity amoung girls with" + model.getFrequencyListName(location));--

what it is telling me is that I need an int method for getFrequencyListName, and I have have one but it is for an array. Obviously the types are different but I am not sure as to what to do or what I have done wrong here and am looking for any help that is given I am going to include both classes of code. Thanks for any help given.

Also I am a beginner and am still learning a lot about Java.

package PA5BlairMain;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Phil
 */
import java.io.*;
import java.util.Scanner;


public class NamesDelegate 
{
    private BabyNamesModel model = new BabyNamesModel();
    
    public NamesDelegate()
    {
        runConsoleInterface();
    }

 public void runConsoleInterface()
{
    Scanner keyboard = new Scanner (System.in);
    
    String searchKey;
    int rank = -1;
    
    //BabyNamesModel.dataTable.searchForaName();
    String line = null;
    System.out.println("Enter a Baby Name: ");
    line = keyboard.nextLine();
    model.getGirlNameData();
    int  location = model.searchForAName(line);
    
    if (location == -1)
    {
        System.out.println("Your Name was not found!");
    
    }
    else
    {
        System.out.println(line +"is ranked at" + location + " in popularity amoung girls with" + model.getFrequencyListName(location));
    }
}
 
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package PA5BlairMain;

/**
 *
 * @author Phil
 */
import java.io.File;
import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class BabyNamesModel 
{
    
    private String [] nameList;
    private int [] frequencyList;
    private boolean dataTable;
    private String tempFileName;
    private String girlNames1;
    private String boyNames1;



public BabyNamesModel()
{  
     nameList = new String[1000];
     frequencyList = new int[1000];
     dataTable = false;
     //tempFileName = "C:/boynames.txt" ;


} 
   	

           
public void readDiskFiles(String tempFileName) 
{ 
       
    
    Scanner inFile;
    
    try
    {
        inFile = new Scanner (new FileInputStream(tempFileName));
            
            if (! inFile.hasNext())
                dataTable = false;
                else
            {
                int i = 0;
                while (inFile.hasNext())
                {
                    nameList [i] = inFile.next();
                        frequencyList[i]=inFile.nextInt();
                    i ++;
                }
                dataTable = true;
            }
     inFile.close();
    
    }
    catch (FileNotFoundException ex)
    {
        System.out.println("There is a problem opening the files!");
        System.exit(0);    
    }

}
public void getGirlNameData()
{
    
   
    readDiskFiles  ("girlnames.txt");
}
public void getBoyNameData()
{
    
   readDiskFiles ("boynames.txt");
}

public int searchForAName (String searchKey)
{
    int i = 0;
    
    boolean found = false;
    
    
    
        while (i <nameList.length && !found)
        {
            if (nameList [i].equalsIgnoreCase(searchKey))
                found = true;
            i ++;
        }
    
    if (found)
        return i;
    else 
        return -1;
}
public int [] getFrequencyListName ()
{
    return frequencyList;

}

    

}
model.getFrequencyListName(location)

returns an array of int[]. So some ways you could do is as below according to your requirements you may choose

1. Either loop though the array and print all the elements of the array.

ex:

for (int i=0;i<model.getFrequencyListName(location).length;i++){
 System.out.println(model.getFrequencyListName(location)[i]);
}

2. If you are sure about the index that you need to call get the particular array index.
ex :

System.out.println(model.getFrequencyListName(location)[0]);

Hey Zaad this was exactly what I was looking for, I did put it into an loop into my other class (babyNamesModel), and I am getting it to work but the numbers are not correct with the specs that I have. Here is what I have updated in the BabyNamesModel class

public int getFrequencyList (int key)
{
   int i = 0;
   boolean found = false;
    
    while (i <frequencyList.length && !found)
        {
            if (frequencyList [i] == key)
                found = true;
            i ++;
        }
    
    if (found)
        return i +1;
    else
        return -1;


}

And here is the output of this application:


Enter a Baby Name:
walter
walter is not ranked among the top 1000 girl names
walter is ranked 356 in popularity amoung boys with 599 namings
BUILD SUCCESSFUL (total time: 9 seconds)

another output for testing:
Enter a Baby Name:
Justice
Justice is ranked 456 in popularity amoung girls with 599 namings
Justice is ranked 401 in popularity amoung boys with 561 namings

The walter one should be 775 namings

and Justice/girl should be 655 namings with boys it should be 653 namings

So I don't know why I am so far off, other than that everything else works fine. But it kinda of boggles me why this isn't working, I am trying to go through and sequentially find all the namings that are like these.

Again thanks for any help given!

One problem in the while loop of the BabyNameModel class is that line 96 is that even after found the variable "i" has incremented and the next issue is that again even after found it keeps on incrementing till the end of the list. If you modify the loop to break as soon as the required is found it would do the trick as follows:

while (i <nameList.length && !found)
{
if (nameList [i].equalsIgnoreCase(searchKey)){
 found = true;
 break;
}
i ++;
}

Also there is the same issue in your modified code while loop it also should be fixed as:

while (i <frequencyList.length && !found)
{
if (frequencyList [i] == key){
found = true;
break;
}
i ++;
}

Hope this would rectify the issues... if not update and let us know

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.