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.

Results 1 to 4 of 4

Thread: Post variable set to non-null vlaues

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Post variable set to non-null vlaues

    Hi,

    I would appreciate help in resolving this issue.

    My specification for Class Employee states:

    Employee()
    //post variables set to non-null values;
    Employee (String nme, char sex, Date dob, int id, Date start)
    //pre start !=null
    //post variables initialised with params passed in


    Class Employee extends class Person.

    This is what i have done for the constructors which I have taken the details from the specification for.

    public class Employee extends Person
    {
        //instance variables
        protected int id;
        protected Date start;
        protected float salary;
     
        //start constructors
        public Employee()
        {
          super();
          id=0;
          salary=0;
          [COLOR="Red"]start=[/COLOR]
     
        }
     
        public Employee(String nme, char sex, Date dob, int number, Date start)
        {
           super (nme, sex, dob);
           id=number;
           start= new Date(start);
           salary=0;
        }
        //end of constructors

    the problem i have is with setting the date (the section highlighted in red) to a non-null value. How do i do this? I have looked over my previous work and found nothing where we have set the initial state for a date.

    Your help will be greatly appreciated.

    Many Thanks


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Post variable set to non-null vlaues

    You can set it to the current Date. Or, the better strategy is to remove that method all-together, since it basically creates an "empty" employee.

    // set the date to the current date
    start = new Date();

  3. #3
    Junior Member
    Join Date
    Oct 2009
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Post variable set to non-null vlaues

    With regards to setting to the current date, i have done that and it works, so thank you.

    As for the constructor itself, to be honest I have a list of things which i need to double check with my tutor, this being one of them.

    The specification requires both constructors, as it states:

    Design and code class Employee, which inherits from Person.
    protected variables
    int id;
    Date start;
    float salary
    constructor
    Employee()
    // post variables set to non-null values;
    Employee (String nme, char sex, Date dob, int id, Date
    start)
    // pre start != null
    // post variables initialised with params passed in
    Note that both these constructors should also call the
    inherited constructor.
    The clone constructor should also call the inherited
    constructor.


    I am unsure of the need for the two constructors, as I understand the second alone would be sufficient.

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Post variable set to non-null vlaues

    Ahh, so the instructor asked for the empty employee constructor method. Yes, ask them about what to do with the start date, but I would leave that first constructor in there.

Similar Threads

  1. !=null
    By ss7 in forum Java Theory & Questions
    Replies: 11
    Last Post: October 31st, 2009, 03:48 PM
  2. Null Pointer Exception
    By MysticDeath in forum Exceptions
    Replies: 2
    Last Post: October 24th, 2009, 02:49 PM
  3. Replies: 6
    Last Post: October 20th, 2009, 07:33 AM
  4. NullPointerException:null problem
    By derky in forum Exceptions
    Replies: 8
    Last Post: September 18th, 2009, 04:06 PM