I have to create a database that implements an array that stores a persons first name and last name and zip code

this is what i have so far for my individuals array

public class IndividualsArray
{
 private Individuals[] array;
 private int count;
 private int zipCode;

  public IndividualsArray ()
   {
     array = new Individuals[5];
      count = 0;
      zipCode = 00000;
   }

  public void addIndividuals (String fName,  String lName, int zipCode)
   {
     if (count == array.length)
        increaseSize();

     array[count] = new Individuals (fName, lName, zipCode);
     zipCode = zipCode;
     count++;
    }

  public String toString()
   {
     String database;

     database += "A List of Individuals\n";

     database += "First Name: " + fName + "\n";
     database += "Last Name: " + lName + "\n";
     database += "Zip Code: " + zipCode + "\n";

     database += "n\nIndividuals Run Down:\n\n";

     for  (int individuals = 0; individuals < count; individuals++)
       database += array[individuals].toString() + "\n";

     return database;
    }

  public void increaseSize ()
   {
     Individuals[] temp = new Individuals[array.length * 3];

     for (int individuals = 0; individuals < array.length; individuals++)
       temp[individuals] = array[individuals];

     array = temp;
    }
}

i get an error msg at these lines:

 database += "First Name: " + fName + "\n";
 database += "Last Name: " + lName + "\n";

saying

IndividualsArray.java:33: cannot find symbol
symbol  : variable fName
location: class IndividualsArray
     database += "First Name: " + fName + "\n";
                                  ^
IndividualsArray.java:34: cannot find symbol
symbol  : variable lName
location: class IndividualsArray
     database += "Last Name: " + lName + "\n";
                             ^

can someone please lend a helping hand......
thank you

Recommended Answers

All 4 Replies

The problem here is that you can't see the fName parameter from the toString() method. This is because fName belongs to the Individual class, not the IndividualArray class. I think that you should remove lines 33-35 since you are outputting your list of Individuals one by one after that anyway.

fName, lName are local variable of addIndividuals() method, therefore you can not use them outside of this method. Hence the zipCode, by some miracle made it (because of the zipCode = zipCode; which may be pure coincidence)
You have to either pass these values as parameters to your toString() method or declare fName, lName in the same manner as zipCode on the start of your class. Sorry, difficult to judge as the code is real mess :S

Should zipCode belong to the Individual class or the IndividualArray class? I think it is a value relating to the Individual, not the list of Individuals.

thank you for all you help, but after i posted my problem i ended up figuring it out.......

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.