Results 1 to 9 of 9

Thread: object attaching - different approach

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    object attaching - different approach

    this thread is similar to the other thread i posted - its not a duplicate

    i wanted to start this new one as a fresh one and not to make things complicated.

    so here it goes


    i have made objects, found an object and wish to assign the found object (mentee) to an existing "experienced" object (mentor)

    i have made a method in the Mentor Class to addMentee(Programmer aMentee)


    it also has an arraylist (the Mentor class has it)

    what i wanna know is how exactly do I attach a Mentor to a Mentee from the Main class where all the checking is happening (like age check, prog lang check etc...)


    and also how would I make a constructor for the Mentor class if we are dealing with object passing (not object creation)

    thanks

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Just use aggregation.
    Code:
    class Mentor{
    
      private Mentee mentee;
     
      public Mentor(Mentee mentee){
       this.mentee = mentee;
      }
    In the main method create a new instance of the mentee class then pass the mentee refrence to the mentor class via the Mentor constructor.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    ty for that

    i get an error

    Mentor.java:37: cannot resolve symbol
    symbol : class Mentee
    location: class Mentor
    public Mentor(Mentee mentee)
    ^
    Mentor.java:114: cannot resolve symbol
    symbol : class Mentee
    location: class Mentor
    private Mentee mentee;
    ^
    Mentor.java:38: cannot resolve symbol
    symbol : constructor Programmer ()
    location: class Programmer
    {
    ^
    3 errors




    code for Mentor:

    Code:
         public Mentor(Mentee mentee)
         {
         	this.mentee = mentee;
         	theMentorings = new ArrayList();  
            
         }    // method: Mentor
    
    //atribs
    
    private Mentee mentee;

    [edit]changed to Mentor mentee and works but then complains about the Programmer class :-/

    Code:
    Mentor.java:38: cannot resolve symbol
    symbol  : constructor Programmer ()
    location: class Programmer
         {
         ^
    1 error
    [/edit]

  4. #4
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Whats the programmer class? Is that the class that contains the main method?

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    no ive attached the files

    its better looked at than to explain each bit. hope u dont mind

    i just wanna be able to assign a Mentee to a Mentor. thats all (easily since im a newbie)

    Application - the menu and stuff but created several objects for testing

    SoftwareHouse - really the main program

    Employee - abstract class

    Programmer - Programmer class

    Mentor - same as Programmer but allows to add/remove a Mentor from a Mentee
    Attached Files Attached Files

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I posted some wonderful code in the other thread, and you didn't even comment on it.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    it is lovely but its a bit too complicated for me you see to understand

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    It is simpler than any of the approaches I've seen from you so far.

    If you don't understand a bit, don't hesitate to ask. But in the other thread, so I have the code at hand.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    ok well kinda got it all working now but it doesnt seem to add the mentee!!!!

    asked for help in the class and they have given me help but for some reason it just doesnt add it.

    ive re attached the code.

    look in the addMenteeMentor(..) method in the SoftwareHouse

    it also wont display the Mentor's mentee's details - guessing because its not added to the arraylist


    thanks
    Attached Files Attached Files

Posting Permissions

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



Click Here to Expand Forum to Full Width