Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 28

Thread: dateOfBirth problems

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default dateOfBirth problems

    Hi, I am doing an assignment that requires me to input a Person with the usual params - name, gender, address, insurance number and date of birth.

    I have managed all but dateOfBirth. I will post the code here. My spec:

    dateOfBirth should be class Date NB: I have another class created called Date. I don't know how to do this

    my constructors spec is like this:

    constructors
    Person() //after this has run, dateOfBirth, name, address, natInscNo != null; and counter incremented

    Person(String nme, char sex, Date dob, String insceNumber)
    // // //
    before this is run dob != null
    after this is run instance variables initialised with params. address != null; counter incremented

    my code for class person, if you need the code for Date or Controller please ask:
     
    public class Person
    {
        // instance variables
        protected String name;
        protected char gender;
        protected Date dateOfBirth;
        protected String address;
        protected String natInsceNo;
     
        private static int counter;
     
        public static int count()
        {
            return counter;
        }
     
        /**
         * Constructor for objects of class Person
         */
        public Person(String nme, char sex, Date dob, String insceNumber)
        {
            // initialise instance variables
            name = nme;
            dateOfBirth = new Date(dob);
            getGender(sex);
            address = "";
            natInsceNo = insceNumber;
            counter = 0;
            counter++;
        }
     
        public Person()
        {
            name = "";
            address = "";
            natInsceNo = "";
            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(Date dob)
        {
            dateOfBirth = dob;
        }
     
        public Date getdateOfBirth(Date dob)
        {
            return dateOfBirth;
        }
     
        public void getGender(char sex)
        {
            gender = sex;        
        }
     
        public void getnatInsceNo(String insceNumber)
        {
            natInsceNo = insceNumber;
        }
     
        public String toString()
        {
            return "Name: " + name + " DOB: " + dateOfBirth + " Gender: " + gender + 
            " Address: " + address + " NatIns No: " + natInsceNo;
        }
     
        public void copy(Person other)
        {
            //creates another instance of Person
            name = other.name;
            gender = other.gender;
            dateOfBirth = other.dateOfBirth;
            natInsceNo = other.natInsceNo;
        }    
     
        public boolean equals(Person other)
        {
            //returns true if the name and national insurance number 
            //are the same as the values in other.
            return name.equals(other.name) && natInsceNo.equals(other.natInsceNo);
        }
    }

    One more thing is, I am using blueJ, and part of my spec is to create a person in there by right clicking on the class person, clicking Person() and then once that is created, I have to set the name, dob etc. then clicking getdateOfBirth() should return the date of birth. But when I type the date of birth in to the box, it says:

    incompatible types, found int but expected date. What do I have to enter to get it as a date? I know strings use "" and chars use ''


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: dateOfBirth problems

    Date is mostly deprecated. Calendar works better.

    However, wouldn't a String work best?

    October 9, 1920

    10/09/1920

  3. The Following User Says Thank You to javapenguin For This Useful Post:

    ibby50 (November 23rd, 2010)

  4. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: dateOfBirth problems

    Hey, yeah it would. But my spec specifies that dateOfBirth should be type Date. I have also just found out that in the controller I need to get the user to input a date of birth, but there isn't a getDate like there is getString or getInt. Any ideas for any of these problems?

  5. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: dateOfBirth problems

     
    static final int JANUARY= 0;
    static final int FEBRUARY = 1;
    static final int MARCH = 2;
    static final int APRIL = 3;
    static final int MAY = 4;
    static final int JUNE = 5;
    static final int JULY = 6;
    static final int AUGUST = 7;
    static final int SEPTEMBER = 8;
    static final int OCTOBER = 9;
    static final int NOVEMBER = 10;
    static final int DECEMBER = 11;
    private int year;
    private int month;
    private int date;
    public Date(int year,
                int month,
                int date)
    {
    year = this.year;
    month = this.month;
    setMonth(month);
    date = this.date;
    }
     
    public void setMonth(int month2)
    {
    month = month2;
    }
     
    public String getMonth()
    {
    if (month == Date.JANUARY)
    return "January";
    else if (month == Date.FEBRUARY)
    return "February";
    else if (month == Date.MARCH)
    return "March";
    else if (month == Date.APRIL)
    return "April";
     
    etc
     
    }

    Also, you'll need a sex and this.sex in and before your constructor in order for the code below to work:
    public Person copy()
    {
    Person p = new Person(this.name, this.sex, this.dateOfBirth, this. natInsceNo);
    return p;
    }

    Also, why isn't the address passed as parameter to constructor? Just curious.

  6. The Following User Says Thank You to javapenguin For This Useful Post:

    ibby50 (November 23rd, 2010)

  7. #5
    Junior Member
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: dateOfBirth problems

    I will try that code, although I am not totally sure if I am allowed to add more instance variables.

    And I tried the code with the this.sex code and it brought back cannot find variable sex

  8. #6
    Junior Member
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: dateOfBirth problems

    public Date(int year, int month, int date)
        {
            year = this.year;
            month = this.month;
            setMonth(month);
            date = this.date;
        }

    brings the error message:

    invalid method declaration; return type required

  9. #7
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: dateOfBirth problems

    Quote Originally Posted by ibby50 View Post
    public Date(int year, int month, int date)
        {
            year = this.year;
            month = this.month;
            setMonth(month);
            date = this.date;
        }

    brings the error message:

    invalid method declaration; return type required
    That's supposed to be the constructor for the Date class.

  10. #8
    Junior Member
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: dateOfBirth problems

    sorry, nothing is supposed to inherit from the date class. I am supposed to set the date of birth as a date type in person depending on what the user inputs and then get the integers again as a string

  11. #9
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: dateOfBirth problems

    Data type?

    Make DOB an object of Date?

    Have a method getDateOfBirth and setDateOfBirth.

    I think that's what they want you to do.

    I don't get
    nothing is supposed to inherit from the Date class
    Well...I did think of something.

    Do you have to pass the DOB as a parameter to person?

    Couldn't you just have a method
    Date d;
    setDateOfBirth(int month, int day, int year)
    {
    d = new Date(month, day, year);
    }

    or something like that.

  12. #10
    Junior Member
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: dateOfBirth problems

    thats all great.

    day, month, and year are all private in my Date class. and dateOfBirth is supposed to be in the Person class.

    The following is from class Person:

    public Person(String nme, char sex, Date dob, String insceNumber)
        {
            // initialise instance variables
            name = nme;
            dateOfBirth = new Date(dob);
            setGender(sex);
            address = "";
            natInsceNo = insceNumber;
            counter = 0;
            counter++;
        }

    public Date getdateOfBirth(Date dob)
        {
            return dateOfBirth;
        }


    And this is my code from the class Date:

    public class Date
    {
        // instance variables
        private int day, month, year;
     
        /**
         * Constructor for objects of class Date
         */
        public Date(int dd, int mm, int yy)
        {
            // initialise instance variables
            day = dd;
            month = mm;
            year = yy;
        }
     
        public Date()
        {
            //sets the default value of day, month and year to 0
            day = month = year = 0;
        }
     
        public int getDay()
        {
            return day;
        }
     
        public int getMonth()
        {
            return month;
        }
     
        public int getYear()
        {
            return year;
        }
     
        public String monthAsString()
        {
            //returns month as a string rather than an integer
            switch (month)
            {
                case 1: return "January";
                case 2: return "February";
                case 3: return "March";
                case 4: return "April";
                case 5: return "May";
                case 6: return "June";
                case 7: return "July";
                case 8: return "August";
                case 9: return "September";
                case 10: return "October";
                case 11: return "November";
                case 12: return "December";
                default: return "";          
            }         
        }
     
        public String toString()
        {
            return day + "/" + month + "/" + year;
        }
     
        public void copy(Date other)
        {
            //creates another instance of Date
            day = other.day;
            month = other.month;
            year = other.year;
        }    
     
        public boolean equals(Date other)
        {
            //returns true if the day, month and year values are the same as the values in other.
            return day == other.day && month == other.month && year == other.year;
        }
     
        public Date(Date other)
        {
            day = other.day;
            month = other.month;
            year = other.year;
        }   
    }

    Bearing in mind that I am not allowed to change any of the private/protected instance variables, or add new ones as far as I am aware. I can't extend to Date in Person and vice versa. All data types need to stay the same and I think the only thing missing is how to input the date when I right click on the class to make the person in BlueJ. Basically I need to be able to enter dob in BlueJ as I have managed to do with nme, sex, addr, and insceNumber. I think it is the Date type that is screwing me over.

    I appreciate all your help. This has to be in by 3:30PM tomorrow UK time so all the haste in the world would be greatly appreciated.
    Thanks.
    Last edited by ibby50; November 23rd, 2010 at 06:23 PM.

  13. #11
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: dateOfBirth problems

    Does your Date class have a getDateOfBirth() method?

    If so, it can call that to get Date of Birth.

    However, I'm not sure how to pass it as parameter to Person class, the Date object that is.

    dateOfBirth = new Date(dob);

    There is no constructor in Date with one parameter so that line above will make an error.

    You'll have to pass it as a parameter with int month, int day, int year in the Person class.

    then
    dateOfBirth = new Date(month, day,year);

    All your getMethods should have no parameters usually.

    The only time you'd probably have a parameter is if your get method was both setting something and then returning a value.

    You do nothing with the parameter dob.

    public boolean equals(Date other)
    {
    //returns true if the day, month and year values are the same as the values in other.
    return day == other.day && month == other.month && year == other.year;
    }

    The method is supposed to return a boolean.

    If the getDay() and getMonth() and getYear() values of the Date in the parameter are all equal to the getDay() and getMonth() and getYear of the current data object(this), then it's true
    otherwise false

  14. #12
    Junior Member
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: dateOfBirth problems

    it doesn't. But I am not sure I can add more methods either to Date. Oh well.

    I did find one thing. In the spec, it says my dateOfBirth instance variable should be class Date

    does that change anything? because that makes me think that they're trying to trick me and I actually AM allowed to extend Date. Although I did ask my tutor and he said that day month and year should all be private.

  15. #13
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: dateOfBirth problems

    public Date(Date other)
    {
    day = other.day;
    month = other.month;
    year = other.year;
    }
    You don't have a method name so it assumes that this thing is a constructor.

    Also, you don't have setMonth(int month), setDay(int day), setYear(int year) methods.

    As I've said before, for the copy,

    create a new Date object and pass it like this.year, this.month, this.day, as parameters.

    then return that object.

    It will create and return a new Date object that won't change when you update the original date values.

  16. #14
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: dateOfBirth problems



    Does the date of birth have to be passed as a parameter?

    If not, you can just do this:

    // note, this is an example

    private Date dateOfBirth;

    public Person(.......)
    {
    dateOfBirth = new Date(1,2,3);
    }

    You just have to pass it the parameters yourself in the constructor.

    or you could do this:

    private Date dateOfBirth;
    public Person(....., int day, int month, int year)
    {
    ......
    dateOfBirth = new Date(day, month, year);
    }

  17. #15
    Junior Member
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: dateOfBirth problems

    the first one I tried and I got an error when I entered the date in BlueJ when creating the person. I entered it like 12,12,12

    that right?

    the second one it gave me an error in the new copy code I used from earlier on.

    what do I do with the dob thing? get rid?

  18. #16
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: dateOfBirth problems

    Oh, I think I might see why it won't just let you pass it as a parameter.

    You do need the day, month, and year as parameters for the Person parameters in order to initialize the dateofbirth object.

    No, I guess you don't have to have the dateofbirth as a parameter.

  19. #17
    Junior Member
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: dateOfBirth problems

    ok done that, now its saying an error in Person copy()

    cannot find symbol constructor Person(java.lang.String,char,java.lang.String)

  20. #18
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: dateOfBirth problems

    You don't have a constructor (String value, char value2, String value3) do you?

    Oh you might.

    Let's see the copy method.

    In fact, show all the code.

  21. #19
    Junior Member
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: dateOfBirth problems

    Ok, this is Date:

    public class Date
    {
        // instance variables
        private int day, month, year;
     
        /**
         * Constructor for objects of class Date
         */
        public Date(int dd, int mm, int yy)
        {
            // initialise instance variables
            day = dd;
            month = mm;
            year = yy;
        }
     
        public Date()
        {
            //sets the default value of day, month and year to 0
            day = month = year = 0;
        }
     
        public int getDay()
        {
            return day;
        }
     
        public int getMonth()
        {
            return month;
        }
     
        public int getYear()
        {
            return year;
        }
     
        public String monthAsString()
        {
            //returns month as a string rather than an integer
            switch (month)
            {
                case 1: return "January";
                case 2: return "February";
                case 3: return "March";
                case 4: return "April";
                case 5: return "May";
                case 6: return "June";
                case 7: return "July";
                case 8: return "August";
                case 9: return "September";
                case 10: return "October";
                case 11: return "November";
                case 12: return "December";
                default: return "";          
            }         
        }
     
        public String toString()
        {
            return day + "/" + month + "/" + year;
        }
     
     
     
        public boolean equals(Date other)
        {
            //returns true if the day, month and year values are the same as the values in other.
            return day == other.day && month == other.month && year == other.year;
        }
     
        public Date(Date other)
        {
            day = other.day;
            month = other.month;
            year = other.year;
        }   
    }

    This is Person:

    public class Person
    {
        // instance variables
        protected String name;
        protected char gender;
        protected Date dateOfBirth;
        protected String address;
        protected String natInsceNo;
     
        private static int counter;
     
        /**
         * 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: " + name + " DOB: " + dateOfBirth + " Gender: " + gender + 
            " Address: " + address + " NatIns No: " + natInsceNo;
        }
     
       public Person copy()
       {
           Person p = new Person(this.name, this.gender, 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.
            return name.equals(other.name) && natInsceNo.equals(other.natInsceNo);
        }
    }

  22. #20
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: dateOfBirth problems

    First of all, how are you initializing the Date object dateofbirth?

    use this.getName,

    or whatever.

    Like if you had soemthing that had a constructor

    String name, int value, char c;

    copy = new classname (this.name, this.value, this.getGender());

    or something like that.

  23. #21
    Junior Member
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: dateOfBirth problems

    i'm sorry I don't understand that

  24. #22
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: dateOfBirth problems

    Ahhhh...I see now.

    Use dob.getDay(), dob.getYear(), dob.getMonth() for the other ones.

  25. #23
    Junior Member
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: dateOfBirth problems

    where abouts do i put them? in the Person copy?

  26. #24
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: dateOfBirth problems

    In the person copy, yes.

    That will copy all the stuff that's current but it won't change if you change the original.

  27. #25
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: dateOfBirth problems

    public class Date
    {
        // instance variables
        private int day, month, year;
     
        /**
         * Constructor for objects of class Date
         */
        public Date(int dd, int mm, int yy)
        {
            // initialise instance variables
            day = dd;
            month = mm;
            year = yy;
        }
     
        public Date()
        {
            //sets the default value of day, month and year to 0
            day = month = year = 0;
        }
     
        public int getDay()
        {
            return day;
        }
     
    public Date getCopy()
    {
    Date copy = new Date(this.day, this.month, this.year);
    return copy;
    }
        public int getMonth()
        {
            return month;
        }
     
        public int getYear()
        {
            return year;
        }
     
        public String monthAsString()
        {
            //returns month as a string rather than an integer
            switch (month)
            {
                case 1: return "January";
                case 2: return "February";
                case 3: return "March";
                case 4: return "April";
                case 5: return "May";
                case 6: return "June";
                case 7: return "July";
                case 8: return "August";
                case 9: return "September";
                case 10: return "October";
                case 11: return "November";
                case 12: return "December";
                default: return "";          
            }         
        }
     
    public void setMonth(int month2)
    {
    if (month2 < =0 || month2 >12)
    System.out.println("What planet are you on?");
     
    month = month2;
    }
     
    public void setDay (int day2)
    {
    if (day2 <= 0 || day2 > 31)
    {
    System.out.prinltn("What planet are you from?");
    day = 1;
    }
     
    if (month == 2 && year %4 ==0 && day2 > 29)
    {
    System.out.prinltn("What planet are you from?");
    day = 1;
    }
     
     
    if (month == 2 && year %4 !=0 && day2 > 28)
    {
    System.out.prinltn("What planet are you from?");
    day = 1;
    }
     
    if ((month == 4 || month == 6 || month ==9 || month ==11) && day2 > 30)
    {
    System.out.prinltn("What planet are you from?");
    day = 1;
    }
     
    day = day2;
     
    }
     
    public void setYear(int year2)
    {
    if (year2 < 0)
    {
    System.out.println("We haven't developed a B.C. method yet.  Sorry.");
    year = 0;
    }
     
    if (year2 > 2010)
    {
    System.out.println("That year hasn't happened yet!");
    year = 2010;
    }
     
    year = year2;
    }
     
    public boolean isLeapYear()
    {
    if (year%4 ==0)
    return true;
    else return false;
    }
        public String toString()
        {
            return getDay + "/" + month + "/" + year;
        }
     
     
     
        public boolean equals(Date other)
        {
            //returns true if the day, month and year values are the same as the values in other.
            if (this.year == other.year && this.month == other.month && this.day = = other.day)
    return true;
    else 
    return false;
        }
     
        public Date(Date other)
        {
            day = other.day;
            month = other.month;
            year = other.year;
        }   
     
    // note, this would work too
     
    public void setData(Date other)
    {
    this.setDay(other.day);
    this.setMonth(other.month);
    this.setYear(other.year);
    }
    }

    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;
     
        }
    }
    Last edited by javapenguin; November 23rd, 2010 at 10:46 PM.

Page 1 of 2 12 LastLast

Similar Threads

  1. 2 problems...
    By Day2Day in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 22nd, 2010, 02:51 PM
  2. [SOLVED] Have a few odd problems.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 18
    Last Post: October 19th, 2010, 06:08 PM
  3. rmi problems
    By deepthought in forum Java SE APIs
    Replies: 7
    Last Post: September 7th, 2010, 07:25 PM
  4. How to compile and run java program?
    By ebalari56 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 27th, 2009, 09:33 PM
  5. If you have any .NET problems
    By antony_t in forum The Cafe
    Replies: 1
    Last Post: August 26th, 2009, 10:49 AM