Results 1 to 9 of 9

Thread: Need help ASAP!

  1. #1

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

    Need help ASAP!

    hi there

    im doing coursework for uni and really need help

    basically we are meant to design a program for a Software Company which employees programmers

    if a new employee (programmer) is added to the company - an experienced programmer is assigned to them

    this will happen if their programming language are the same

    but i have assumed that the older the person is the more experienced they can be and yes i know there is going to be a flame war - this is just a temp thing



    all my code works fine and now im stuck on addng the Mentee and Mentor (and later on removing them)


    right - we are using abstract class and polymorphism etc...


    Classes I have:

    Main/Application (menu etc..)

    SoftwareHouse

    Employee (Abstract Class)

    Programmer

    Mentor (specialisation of the Programmer class)


    1 Arraylist is in the SoftwareHouse called theStaff and stores the programmers info:

    Name, payroll number, basic salary and programming language

    then there is another arraylist named theMentee (we can change this) which is in the Programmer class - this will hold the Mentee's object so each experienced/senior programmer is assigned to or is "monitoring" the Mentee



    for each mentee a mentor is assigned to - they will get a 5% increase in salary for every mentee they have. thats cool i can do it (I thnk)


    part im stuck on is adding / assiging the mentee and mentor.


    the code you will need to look at if you wish to is attached.

    I need help with adding a Mentee to Mentor and would appreciate any help.

    please explain in easy to understand words

    Thanks
    Attached Files Attached Files
    Last edited by Techno; Nov 12th, 2003 at 04:04 PM.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You're confusing me. All I noticed was that Mentor is a specialization of Programmer. This is not good. Mentor is not an enhancement or specialization of Programmer, it's a status. The Mentor status comes and goes as Mentees come and go, and you shouldn't have to recreate the object everytime the status changes.

    What you need is some experience value in the Programmer class, to find out which programers are elegible for being assigned Mentees. If you want to enhance your app, you could make the experience grow over time, whatever time may mean.

    Code:
    class Programmer {
      protected static final float THRESHOLDMENTEE = 100.0f;
      protected static final float THRESHOLDMENTOR = 200.0f;
      protected static final float MENTEEBONUS = .05f;
    
      protected float salary;
      protected float experience;
      protected ArrayList mentees;
      protected Programmer mentor;
    
      public canMentor() {
        return experience > THRESHOLDMENTOR;
      }
      public needsMentor() {
        return experience < THRESHOLDMENTEE;
      }
      public addMentee(Programmer p) {
        if(!canMentor() || !p.needsMentor())
          throw new someException();
        mentees.add(p);
      }
      public getSalary() {
        float mentbonus = mentees.getSize() * MENTEEBONUS;
        return (1.0f+mentbonus)*salary;
      }
      // etc...
    }
    When the experience level increases over the lower threshold the mentee must remove itself from the list of mentees of the mentor.
    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.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    thanks for the reply - i truely appreciate it


    i may be wrong in my termanology - excuse me


    we havent dealt with throw exception etc.. at all so im confused

    we have a seperate method in the Mentor class which is "theBasicMonthlySalary" and it basically takes the current salary and adds 0.5 to it - so we can excuse this from the problem

    the only problem is adding mentee to mentor

    this is complicated so bear with me

    the new code is attached (just some additions in the SoftwareHouse class)


    so how would I add from the softwareHouse - the mentee to mentor?

    :-/ how to pass an object (the Mentee object) to the programmer method called addMenteeMentor(Programmer aMentee) and then this code should add to the arraylist the object or pass it to the Mentor - i dunno thats where im stuck

    help!
    Attached Files Attached Files

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Sorry, I don't see the problem.

    You can simply ignore the exception throwing, it's just a test.
    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.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Sorry, it's nearly midnight here, else I'd scrape up a complete sample app. But now I'm going to bed. See you around.
    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.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    in the Programmer Class - do i need the addMenteeMentor(Programmer p) method at all? or shall i just leave it in the Mentor Class?

    if thats the case - how exactly do i add the Mentee object in the arraylist of the Mentors' class?

    thats what im confused on

    is my code correct for the SoftwareHouse?

    sure - np hopefuly 2morrow

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Ok, I wrote something. I don't have a Mentor class, as I said I think it is bad design to have one. I don't have an Employee class either, but it would be easy to add.

    Code:
    import java.util.*;
    
    class Programmer {
    	protected static final float THRESHOLDMENTEE = 100.0f;
    	protected static final float THRESHOLDMENTOR = 200.0f;
    	protected static final float MENTEEBONUS = .05f;
    	public static final float INITIALSALARY = 130.0f
    
    	// Possible values for language
    	public static final int C = 0;
    	public static final int CPLUSPLUS = 1;
    	public static final int CSHARP = 2;
    	public static final int JAVA = 3;
    	public static final int VISUALBASIC = 4;
    
    	protected float salary;
    	protected float experience;
    	protected ArrayList mentees = new ArrayList();
    	protected Programmer mentor = null;
    	protected int language;
    
    	public Programmer(int lang) {
    		language = lang;
    		salary = INITIALSALARY;
    		experience = 0.0f;
    	}
    	public Programmer(int lang, float initSal, float initExp) {
    		language = lang;
    		salaray = initSal;
    		experience = initExp;
    	}
    
    	public boolean canMentor() {
    		return experience > THRESHOLDMENTOR;
    	}
    	public boolean needsMentor() {
    		return experience < THRESHOLDMENTEE;
    	}
    	public void addMentee(Programmer p) {
    		if(!canMentor() || !p.needsMentor() || p.language != language)
    			throw new IllegalArgumentException();
    		mentees.add(p);
    		p.mentor = this;
    	}
    	public float getSalary() {
    		float mentbonus = mentees.size() * MENTEEBONUS;
    		return (1.0f+mentbonus)*salary;
    	}
    	public boolean isMentor() {
    		return !mentees.isEmpty();
    	}
    	public boolean isMentee() {
    		return mentor != null;
    	}
    	public int getLanguage() {
    		return language;
    	}
    	public int getMenteeCount() {
    		return mentees.size();
    	}
    }
    
    class SoftwareHouse {
    	// TreeSet is useful for fast lookups
    	private TreeSet programmers = new TreeSet();
    
    	/** Employs a new Programmer */
    	public void employ(Programmer p) {
    		// Check if not already employed
    		if(!programmers.contains(p)) {
    			programmers.add(p);
    			if(p.needsMentor() && !p.isMentee()) {
    				findMentor().addMentee(p);
    		}
    	}
    
    	/** Searches a programmer with as little mentees as possible 
    	 * who has the same language as the mentee
    	 */
    	public Programmer findMentor(Programmer mentee) {
    		Iterator it = programmers.iterator();
    		Programmer store = null;
    		int menteeLang = mentee.getLanguage();
    		while(it.hasNext()) {
    			Programmer p = (Programmer)it.next();
    			if(p.canMentor() && p.getLanguage() == menteeLang &&
    				(store == null ||
    				p.getMenteeCount() < store.getMenteeCount())) {
    				store = p;
    			}
    		}
    		if(store == null) {
    			// Didn't find a suitable mentor, you need to handle this!
    		}
    		return store;
    	}
    }
    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.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    thx for that regarding the other topic here are a few things i dont understand


    1) i know the solution is right there but i still dont understand how to add a Mentee to the other arrayList (in the Mentor Class)

    in my OWN code - everything has been done and matched etc... an appropriate mentor has been found for this mentee - all checks/conditions have been made. its just assigning it to the mentor that i am stuck on.

    I also have a Mentor class (if i didnt explain before) which holds the mentee's and a method to increase the salary by 10% (or 5%) for every mentee they have.


    how do I do this? that is really i dont understand and i hope you can help

    ty

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Is the Mentor class in the requirements? Because, as I explained in this very thread, it is bad practice to have this Mentor class.

    To add a mentee to the ArrayList, simply call ArrayList.add and pass the mentee. You might want to check if the mentee doesn't already have a mentor.

    In databases, the thing is called a 1:n relation: 1 mentor references n mentees, n mentees reference 1 mentor. This means that each mentor has the ArrayList to store the n mentees and each mentee has a single reference in which to store the mentor.

    The mentor is simply assigned to this reference to establish the link from mentee to mentor.
    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.

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