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;
}
}