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
Last edited by Techno; Nov 12th, 2003 at 04:04 PM.
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.
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
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.
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
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.