assignment problem with List<T>
Hi, I'm new to java i'm having a problem assigning a string from a string list.
the code, gets a random number and chooses a sex, m/f if female tries to assign a name based on a list of girlnames otherwise a list of boynames.
error: method girlNames(int) is undefined...
I haven't used List<T> before so I'm not quite sure how to assign it to a string. Also once I have assigned it I want to delete the element from the list so that there is no Bunnies with duplicate names. So should I then use clear(); and this will remove the element?
Code:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class BunnyCreation
{
private static final String BOY_NAMES = "names/boynames.txt";
private static final String GIRL_NAMES = "names/girlnames.txt";
private List<String> boyNames = new ArrayList<String>(1000);
private List<String> girlNames = new ArrayList<String>(1000);
public void generateBunny()
{
boolean female;
int i = (int)getRandom(20);
if (i>10)
female=true;
else
female=false;
if (female)
{
int girlIndex = (int)getRandom(1000);
String name = girlNames(girlIndex); // ERROR HERE : method girlNames(int) is undefined
}
}
/**
* Adds all names from both boys/girls files to appropiate Lists.
*/
public void initializeLists()
{
try
{
String inStr;
Scanner inFile = new Scanner(new FileInputStream(BOY_NAMES));
while (inFile.hasNextLine())
{
inStr = inFile.nextLine();
boyNames.add(inStr);
}
inFile.close();
inFile = new Scanner(new FileInputStream(GIRL_NAMES));
while (inFile.hasNextLine())
{
inStr = inFile.nextLine();
girlNames.add(inStr);
}
inFile.close();
}
catch(FileNotFoundException fnfe)
{
fnfe.printStackTrace();
System.out.println("File not found: " + BOY_NAMES);
System.out.println("File not found: " + GIRL_NAMES);
}
}
/**
* Prints out Girl names / Boy names.
*/
public void printList()
{
for (String gname : girlNames)
System.out.println((gname));
for (String bname : boyNames)
System.out.println((bname));
/*
for (Iterator it = girlNames.iterator(); it.hasNext();)
System.out.println(((String)it.next()));
for (Iterator it = boyNames.iterator(); it.hasNext();)
{
String name = (String)it.next();
System.out.println(name);
}
//*/
}
public double getRandom(int numOutOf)
{
double temp = Math.random();
return (temp *= numOutOf);
}
}