Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing arrays to methods, can´t resolve symbol

Status
Not open for further replies.

petold

Programmer
Sep 18, 2002
9
SE
Hi
i´m a newbie at java-programming and im not an english spoken man but i´ll try to make you understand my problem. When i´m trying to pass an array to a method, the compailer says it cant resolve symbol. I´ve read my java-book and it isn´t helping.....
This is the code:
//MedelAlder.java

import java.util.*;

public class MedelAlder
{
public static void main ( String args [] )
{

final int NUMBER_OF_STUDENTS = 2;
Person n[] = new Person [NUMBER_OF_STUDENTS + 1];


for ( int i = 1; i <= NUMBER_OF_STUDENTS; i++)
{

ConsoleInput cin = new ConsoleInput ();
System.out.println(&quot;\nType your first name, last name and personal number:&quot;);
System.out.println(&quot;(Delimit your input with ','(e.g FirstName,lastName,birthDate)) &quot;);

String s1 = cin.readString ();
StringTokenizer st = new StringTokenizer(s1, &quot;,&quot;);
String firstName = st.nextToken();
String lastName = st.nextToken();
String birthDate = st.nextToken();


Person a = new Person();
a.setFirstName(firstName);
a.setLastName(lastName);
a.setBirthDate(birthDate);


n = a ;
}

if ( notEqualBirthDates (n) )
{
System.out.println (&quot;\n*****************************************\n&quot;+
&quot;FirstName&quot; + &quot;\t&quot; + &quot;LastName&quot; + &quot; \t&quot; + &quot;BirthDate\n&quot;+
&quot;---------&quot; + &quot;\t&quot; + &quot;--------&quot; + &quot; \t&quot; + &quot;---------\n&quot;);

for ( int i = 1; i <= NUMBER_OF_STUDENTS; i++ )

{
System.out.println (&quot;\n&quot; + i + &quot;)&quot; + &quot; &quot; + n + &quot;&quot; );
}
}
else
{
System.out.println(&quot;That can not be true, check your birthdates&quot;);

}
}
}

----------------------------------------------------------


//Person.java


public class Person
{
private String firstName;
private String lastName;
private String birthDate;


public Person ()
{

}

public Person ( String fName, String lName, String bDate )
{
firstName = fName;
lastName = lName;
birthDate = bDate;


}

public void setFirstName ( String firstName )
{
this.firstName = firstName;
}

public String getFirstName ()
{
return firstName;
}


public void setLastName(String lastName)
{
this.lastName = lastName;
}

public String getLastName ()
{
return lastName;
}

public void setBirthDate ( String birthDate )
{
this.birthDate = birthDate;
}

public String getBirthDate ()
{
return birthDate;
}


public static boolean notEqualBirthDates ( Person p[] )
{
boolean x = true;
//Stegar index på strängen
for ( int i = 1 ; i < p.length - 1 ; i++ )
{
//Stegar tecken från 1 till 9 och jämför med index
for (int j = i + 1 ; j < p.length ; j++ )
{
if ( p.getBirthDate() == p[j].getBirthDate() )
{
x = false;
return x;
}
}
}
return x;
}


public String toString ()
{
return ( firstName + &quot;\t &quot; + lastName + &quot;\t\t&quot; + birthDate + &quot;.&quot; );

}
}
-----------------------------------------------------------

the compiler says:
MedelAlder.java:37: cannot resolve symbol
symbol : method notEqualBirthDates (Person[])
location: class MedelAlder
if ( notEqualBirthDates (n) )
^
1 error

Tool completed with exit code 1

---------------------------------------------------------

Hope that someone out there can help me.
 
notEqualBirthdates is a method in Person. You must call it on a person object:

Person [] parray = new Person[10];
Person p = new Person();
p.notEqualBirthDates(parray);
 
wow,thats a quick reply......

Thx very much, that did the trick, now i must get the method to work properly....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top