java help plz :(

Tech

Registered User.
Local time
Today, 10:51
Joined
Oct 31, 2002
Messages
267
hi there

I REALLY need big time java help for my coursework

PLEASE explain in easy to understand words - im a newbie at java

basically we are meant to design a program that is for a softwarehouse company

it employees programmers

when NEW programmers are joined to the company, an experienced programmer is assigned to them - if they have the same programming language


thats basically the trouble im having


my code is attached in the zip file but i really am stuck in assigning a mentor to mentee.


this is really doing my head in since the past week

please please help :(

to be honest - im cracking up and about to cry for real :(
 

Attachments

im debugging as we speak

it doesnt execute the iff statement where it is attaching the mentor and mentee

i am figuring out why but please help
 
1) This is not a java forum
2) We dont do homework
3) Your code is messy
4) Where is the error?
5) Goto 1

Jon
 
im not expecting you to do the work for me - hell no

im not like that

i know its not a java forum - i posted in the watercooler forum and Rich said its best to post here and took the advice

code is not messy - thats not an excuse not to look at it

and no - i dont expect you to do the work for me

i want to know WHERE the problem is or really HOW to solve it

TY
 
Tech said:
im not expecting you to do the work for me - hell no

im not like that

i know its not a java forum - i posted in the watercooler forum and Rich said its best to post here and took the advice

code is not messy - thats not an excuse not to look at it

and no - i dont expect you to do the work for me

i want to know WHERE the problem is or really HOW to solve it

TY

Yes code is very messy you have commented out classes functions, its hard to follow. WHERE is your error?
Do you have an error we should look at...you just said you dont want us to do it...and then you say how do i do it!!!

Do it first then come back with problems and maybe someone will help.
 
error is it wont attach mentee to mentor

sometimes it gives a runtime error on like 261/262 or there abouts in the SoftwareHouse addMenteeToMentor() method
 
real problem is the casting issue

i want to cast the current prog to a Mentor

Code:
prog = (Mentor)prog

this code was given by an "assistant" in java class today

i re coded the method to add the mentee and mentor in the softwarehouse:

Code:
//Find the eldest one in the employee
if(menteeage < anotherage && mentorproglang.equals(thisproglang) && foundpn == true)
{
ConsoleIO.out.println("Mentor age: " + anotherage);
ConsoleIO.out.println("Mentor pn : " + mentorpn);
ConsoleIO.out.println("Mentor pl : " + mentorproglang);
foundMentor = true;
prog = (Mentor)prog; //HERE IS THE ERROR

..
..


the runtime error is this:

Code:
Exception in thread "main" java.lang.ClassCastException
        at SoftwareHouse.addMenteeToMentor(SoftwareHouse.java:257)
        at Application.run(Application.java:72)
        at Main.main(Main.java:15)

what does this mean and how can i solve it?
 
Tech said:
error is it wont attach mentee to mentor

sometimes it gives a runtime error on like 261/262 or there abouts in the SoftwareHouse addMenteeToMentor() method

2 things.

1) does the addMenteeFunction know what
if(menteeage < mentorage)
{...
} is ???
Is menteeage "this" (the invoking object?

2) you cannot do:
ConsoleIO.out.println("Attaching Mentee to Mentor (payrollnumber = " + mentorpn + ") ....\n\n");

mentorpn is an object (A mentor)
you need to do:
ConsoleIO.out.println("Attaching Mentee to Mentor (payrollnumber = " + mentorpn.getPayRollNumber() + ") ....\n\n");

Jon
 
Cant cast a programmer to a mentorer...they aren't the same...
why dont you call a method to re-create the programmer as a mentorer?

The cast is only valid if your object extends that class.

jon
 
ty

i was going to ask this

i re modified the code to read this: (in the addMenteeMentor)

Code:
if(proceedattachment.equalsIgnoreCase("y"))   
{   
ConsoleIO.out.println("Attaching Mentee to Mentor (payrollnumber = " + mentorpn + ") ....\n\n"); 
anotherage = 0;
	
iter = theStaff.iterator();        
while(iter.hasNext() == true)        
{ 
Programmer prog = (Programmer)iter.next(); //MENTOR	- MENTOR is type of programmer

mentorproglang = prog.getCertainLang(); //get its programming language again		
mentorage = prog.getAge();
			
//Make sure ALL conditions match and if so - then add the Mentee to Mentor

if(menteeage < mentorage)
{
if((mentorage > anotherage) && (mentorproglang.equals(thisproglang)) && (foundpn == true))
{
                anotherage = mentorage;
                foundMentor = true;
                details = prog.toString();
ConsoleIO.out.println("Details of Mentor:\n" + details + "\n\n");

//make this programmer record a Mentor since we found out it IS a mentor
						((Mentor)prog).addMentee(mentee);	   	
}
}        
}			
}

yes i get an error at the ((Mentor)prog).addMentee(mentee);



I dont know how to cast it (the prog) to a Mentor since they ARE the same types of objects and the CORRECT record is shown when i add a system.out.println(prog.toString());

it points to the correct record - but need to know how to cast it being a Mentor successfully


any ideas Sir? :)
 
Tech if mentor extends the Programmer interface (class)
then do this:

Programmer P = new Programmer(m); //m in this case is a mentorer.

Programmer should have a constructor which takes 'm' a metorer as a parameter, that will promote it.
Inside of m's constructor make a call to super(); so that it calls the default constructor of a programmer.

Jon
 

Users who are viewing this thread

Back
Top Bottom