Results 1 to 8 of 8
  1. #1
    fh84 is offline Member
    Join Date
    Oct 2009
    Posts
    10
    Rep Power
    0

    Default The constructor Person(String, String, Date) is undefined

    hello to all,
    Java Code:
    public class Employee extends Person
    {
    	protected int id;
    	protected Date start;
    	protected float salary;
    public Employee(String nme, char sex, Date dob, int idIn, Date startIn)
    	{
    		super(nme, sex, dob);
    		id = idIn;
    		start = new Date(startIn);
    	}
    public Employee(Employee other)
    	 {//Class Employee: clone(Constructor)
    		 super(other.name, other.gender, other.dateOfBirth);		
    	    salary=other.salary;
            id=other.id;
            start=new Date(other.start);
    	 }//Class Employee: clone(Constructor)	
    }
    On this example, am trying to create a clone by copying all the values from the constructor. I am also using inheritance, so the Employee is a kind of Person.
    The thing is that the clone is expecting gender to be char but is a string.
    On Personís class I have done the conversion
    gender = Character.toString(sex) but it seams not to like it on the clone.

    Could you please help me?
    Thank you in advanced

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

    Default

    I'm sorry, but I have to ask: has this been cross-posted anywhere?

  3. #3
    fh84 is offline Member
    Join Date
    Oct 2009
    Posts
    10
    Rep Power
    0

    Default

    no and i have no reason to lie because i know you will find out.
    could you please help me?
    thank you!

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

    Default

    I'll help if I can, but you'll need to post your Person class.

    ... and I don't want you to not cross-post without attribution because you know you won't get away with it, I want you to understand why it bugged us so.

  5. #5
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    Java Code:
    if( sex.equalsIgnoreCase("m") )
       gender = 'm';
    else
       gender = 'f';
    OR

    Java Code:
    super(other.name, (other.gender.equalsIgnoreCase("m") ? 'm' : 'f'), other.dateOfBirth);
    OR

    Java Code:
     sex.charAt(0);
    Last edited by mrmatt1111; 11-03-2009 at 03:04 AM.
    My Hobby Project: LegacyClone

  6. #6
    fh84 is offline Member
    Join Date
    Oct 2009
    Posts
    10
    Rep Power
    0

    Default

    so this is the Person class

    Java Code:
    public class Person
    {
        protected String name;  
        protected String gender;      //protected attributes are visible in the subclass
        protected Date dateOfBirth;
        protected String address;
        protected String natInsceNo;
        protected String phoneNo;
        private int counter;//private class
        public String str;
        public static Date myDate;
    
    //Constructor Starts, (returns a new object, may set an object's initial state)
        public Person()
        {
         dateOfBirth = new Date();
         name = "";
         address = this.getAddress();
         natInsceNo = this.setNatInsceNo(str);
         phoneNo = this.getphoneNo();
         counter++;
        }    
        
     public Person(String nme, char sex, Date dob)
     {
         gender = Character.toString(sex);
         name = nme;
         address = this.getAddress();
         natInsceNo = this.setNatInsceNo(str);
         dateOfBirth = dob;
         phoneNo = this.getphoneNo();
         counter++;
     }   
     
     public Person(Person other)
     {//Class Person: clone(Constructor)
      name = other.name;
      address = other.address;
      natInsceNo = other.natInsceNo;
      phoneNo = other.phoneNo;
      dateOfBirth = other.dateOfBirth;
      gender = other.gender;
     }//Class Person: clone(Constructor)
     
    //Constructor Ends, (returns a new object, may set an object's initial state)
        
    //Accessors Starts, (Returns info about the state of an object )
     public int count()
     {
      return counter;
     }//returns persons have been created
    
     public String getGender()
     {
        if ("m".equalsIgnoreCase(gender))
         return "Male";
        else if ("f".equalsIgnoreCase(gender))
         return "Female";
        else 
         return "Wrong Input"; 
     } 
    
        public boolean equals(Person other)
        {
         return name.equals(other.name) && natInsceNo.equals(other.natInsceNo) && dateOfBirth.equals(other.dateOfBirth);
        }//return true if all are true
        
        public String getName()
        {
           return name;
        }//post name is set to nme
        
        public Date getDateOfBirth()
        {
           return dateOfBirth;
        }//post name is set to nme
        
        public String getAddress()
        {
            return address;
        }//post address is set to addr
        
        public String getNatInsceNo()
        {
            return natInsceNo;
        }//post natInsceNo is set to ins
    
        public String getphoneNo()
        {
            return phoneNo;
        }//post natphoneNo is set to phone  
        
     public void copy(Person other)
     {
      name = other.name;
      address = other.address;
      natInsceNo = other.natInsceNo;
      phoneNo = other.phoneNo;
      dateOfBirth = other.dateOfBirth;
      gender = other.gender;
     }
    
    //Accessors Ends, (Returns info about the state of an object )    
        
        
        
    //Transformer Starts, ( Returns nothing, alter the state of an object )
        public void setName(String nme)
        {
           name = nme;
        }//post name is set to nme    
        
        public void setGender(char sex)
    	{
    		 gender = Character.toString(sex);
    	}
    
        public void setAddress(String addr)
        {
            address = addr;
        }//post address is set to addr
            
        public String setNatInsceNo(String ins)
        {
          return  natInsceNo = ins;
        }//post natInsceNo is set to ins
        
    
        public void setphoneNo(String phone)
        {
            phoneNo = phone;
        }//post natphoneNo is set to phone
        
        public String toString()
        {
         return(("Name: ")+name+(" Address: ")+address+(" NaIncNo: ")+natInsceNo+(" PhoneNo: ")+phoneNo);
        }
    //Transformer Ends    
    }//end of class Person

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

    Default

    OK first for the easy stuff:
    You first should go to the java.util.Date API and check out the constructors that Date has available. Is there one that takes a Date parameter as you are trying to do here?
    Java Code:
    start = new Date(startIn);
    I've provided you with a link to make it easier.

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

    Default

    Now a trick for you. You try to make a copy constructor like so:
    Java Code:
      public Employee(Employee other) {
        super(other.name, other.gender, other.dateOfBirth);
        //...
    But the compiler is telling you that this is wrong because Person doesn't have a constructor that takes String, String, Date. It does have one that takes String, char, Date, but there's an even simpler super constructor you can use her. The trick is Employee s a Person, this includes the Employee "other". So you can simply use Person's copy constructor here:

    Java Code:
      public Employee(Employee other) {
        super(other); // because other IS a Person
        //....
    You still have to copy the non-Person attributes from other into the new Employee object, but this makes it easy to copy the Person portion of other into the new object.

Similar Threads

  1. [SOLVED] Dynamic String -> Date Handeling
    By vagetoanima in forum Advanced Java
    Replies: 2
    Last Post: 03-31-2009, 07:43 PM
  2. Replies: 2
    Last Post: 09-18-2008, 08:30 AM
  3. Converting Epoch to string Date
    By amyedwards in forum New To Java
    Replies: 3
    Last Post: 12-14-2007, 11:33 PM
  4. String to Date conversion
    By javaplus in forum New To Java
    Replies: 2
    Last Post: 11-06-2007, 08:16 PM
  5. Date as String to TimeStamp
    By ironballs in forum Advanced Java
    Replies: 1
    Last Post: 08-01-2007, 02:43 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
  •