public class Person
{
// instance variables
private String name;
private char gender;
private Date dateOfBirth;
private String address;
private String natInsceNo;
private static int counter = 0; // you need to initialize it.
// it seems your counter isn't doing much
// it won't keep going up every time you create a new Person.
// the counter only works for that particular Person
// what are you counting by the way?
// if it's how many people you've created, put them in an array or ArrayList, preferably an ArrayList as it can keep growing.
// private ArrayList<Person> personList = new ArrayList<Person>();
// every time you add a new Person
// personList.add(thatPerson);
/**
* Constructor for objects of class Person
*/
public Person()
{
name = "";
address = "";
natInsceNo = "";
counter++;
}
public Person(String nme, char sex, int day, int month, int year, String insceNumber)
{
// initialise instance variables
name = nme;
dateOfBirth = new Date(day, month, year);
setGender(sex);
address = "";
natInsceNo = insceNumber;
counter = 0;
counter++;
}
public static int count()
{
return counter;
}
public void setName(String nme)
{
name = nme;
}
public String getName()
{
return name;
}
public void setAddress(String addr)
{
address = addr;
}
public String getAddress()
{
return address;
}
public void setdateOfBirth(int day, int month, int year)
{
dateOfBirth = new Date(day, month, year);
}
public Date getdateOfBirth()
{
return dateOfBirth;
}
public void setGender(char sex)
{
gender = sex;
}
public char getGender()
{
return gender;
}
public void setnatInsceNo(String insceNumber)
{
natInsceNo = insceNumber;
}
public String getnatInsceNo()
{
return natInsceNo;
}
public String toString()
{
return "Name: " + getname() + " DOB: " + getDateOfBirth() + " Gender: " + getGender() +
" Address: " + getAddress() + " NatIns No: " + getnatInsceNo();
}
public Person copy()
{
Person p = new Person(this.name, this.gender, dob.getDay(), dob.getMonth, dob.getYear(), this.natInsceNo);
return p;
}
public boolean equals(Person other)
{
//returns true if the name and national insurance number
//are the same as the values in other.
if (this.name.equals(other.name) && this.natInsceNo.equals(other.natInsceNo))
return true;
else
return false;
}
}