Im a student programmer so only been studying since september. Had an assignment this week to read in data from a text file called datingdata.txt and create a class for the information storing each persons info in a position of an array. The data was in the format ‘George Robson M 38 11000’ where the name was up to 20 characters. Then we had to compare each person for matches, where they were of an opposite sex, within 5 years of each other in age and had at least 3 common interests (the 1 meaning they were interested in that activity and 0 if not). I have got it working up to the nested for loops at the end and have a feeling I am missing brackets because it keeps coming up with an error that it cannot find symbols. Any help?
import java.io.*;
import static java.lang.Math.*;
class PersonInfo
{
String name;
char sex;
int age;
String interest;
public void setname (String anyName)
{ name = anyName; }
public void setsex (char anysex)
{ sex = anysex; }
public void setage (int anyage)
{ age = anyage; }
public void setinterest (String anyinterest)
{ interest = anyinterest; }
public String getName ()
{ return name; }
public char getsex ()
{ return sex; }
public int getage ()
{return age; }
public String getinterest ()
{return interest; }
void print ()
{
System.out.println(name + " " + sex + " " + age + " " + interest);
}
PersonInfo (String name, char sex, int age, String interest)
{
this.name = name;
this.sex = sex;
this.age = age;
this.interest = interest;
}
}
class Practical6
{
public static void main(String[] args) throws IOException
{
//read in file
BufferedReader fileInput;
fileInput = new BufferedReader(new FileReader("datingdata.txt"));
//create an array for storing each persons information
PersonInfo[] People = new PersonInfo[20];
//fields to use in creating PersonInfo
String name;
char sex;
int age;
String interest;
int i = 0;
int count = 0;
//read in each line and store in an array
while (fileInput.ready ())
{
String information;
information = fileInput.readLine ();
// System.out.println (information);
name = information.substring(0,20);
sex = information.charAt(20);
age = Integer.parseInt(information.substring(22,24));
interest = information.substring(25,30);
People[i]= new PersonInfo (name, sex, age, interest);
i++;
}
fileInput.close();
//pring out the array
for (int j = 0; j < People.length; j++)
People[j].print();
//go through each element of array and compare to another record for a match
for (int k = 0; k < People.length; k++)
for (int l = 0; l <People.length; l++)
if (People[k].getsex() != People[l].getsex())
if(math.abs(People[k].getage()-People[l].getage()) <=5)
{for(int m = 0; m < 5; m++)
if((People[k].getinterest.charAt(m)=='1') && (People[l].getinterest.charAt(m)=='1'));
count++;
if(count==3)
System.out.println(People[k].getname + " is a match with " + People[l].getname);
}
}
}
some syntax error:
1. Math.abs() instead of math.abs()
2. getinterest() instead of getinterest
3. getName() instead of getname