Results 1 to 6 of 6
  1. #1
    andrewkay is offline Member
    Join Date
    Oct 2011
    Posts
    7
    Rep Power
    0

    Default help with java class!!

    hello guys im stuck on how to construct constructors in class person this is what is required.....

    Design and code class Person.

    protected instance variables
    name // String
    gender // char
    dateOfBirth // class Date
    address // String
    natInsceNo // String
    phoneNo // String
    indexNumber // integer
    private class variable
    counter // integer

    constructors
    Person()
    // post dateOfBirth, name, address, natInscNo != null;
    // counter incremented

    Person(String nme, char sex, Date dob)
    // post instance variables initialised with params
    // address != null; natInsceNo != null; counter incremented

    this is what ive done so far on it.......

    public class Person
    {
    variables
    protected String name
    protected char gender
    protected //not sure how to fill this in
    protected String address
    protected String natInsceNo
    protected String phoneNo
    protected int indexNumber
    private int counter

    constructors
    public Person
    {
    //not sure how to construct this
    }
    public Person( String nme, char sex, Date dob)
    {
    name = nme
    gender = sex
    dateofBirth = dob //not sure if this is right
    }
    }

    ive used "//" which im having trouble with any help would be great thanks.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: help with java class!!

    You do the Date variable same as all the other variables. Give it a try, you've nothing to lose. Then if it doesn't work, come back with your code, but please use code tags when posting code. i.e.,

    [code]
    your code here
    [/code]

    Note the bottom code tag is different from the top.

  3. #3
    andrewkay is offline Member
    Join Date
    Oct 2011
    Posts
    7
    Rep Power
    0

    Default Re: help with java class!!

    so what would the type be for dateofBirth.....would it be date

  4. #4
    andrewkay is offline Member
    Join Date
    Oct 2011
    Posts
    7
    Rep Power
    0

    Default Re: help with java class!!

    and also how would you code the first constructor ie

    constructors
    Person()
    // post dateOfBirth, name, address, natInscNo != null;
    // counter incremented

    how would that be coded exactly thanks

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: help with java class!!

    Quote Originally Posted by andrewkay View Post
    so what would the type be for dateofBirth.....would it be date
    The instructions tell you exactly what the type is just as they do for the other types -- there's no ambiguity. The only difference is you'll have to import this class for the code to work (in the java.util package).

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: help with java class!!

    Quote Originally Posted by andrewkay View Post
    and also how would you code the first constructor ie

    constructors
    Person()
    // post dateOfBirth, name, address, natInscNo != null;
    // counter incremented

    how would that be coded exactly thanks
    Try to figure out how to give some default values to these fields. Again, you've nothing to lose to try to do solve this first yourself and all to gain.

    Best of luck!

    Edit: as a hint, the String values will be easy to fill in with a default non-null value. As for the Date, you could just create a Date object that defaults to today using its default constructor. As for the natInscNo, I imagine you'd use the static counter variable to help you create that.
    Last edited by Fubarable; 10-21-2011 at 12:52 AM.

Similar Threads

  1. Replies: 1
    Last Post: 05-31-2009, 11:57 PM
  2. Replies: 1
    Last Post: 05-31-2009, 03:17 PM
  3. Replies: 16
    Last Post: 05-28-2009, 04:41 PM
  4. Replies: 14
    Last Post: 05-28-2009, 06:44 AM
  5. class.java to class.exe
    By f_the_cook in forum New To Java
    Replies: 11
    Last Post: 07-16-2008, 03:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •