I am currently working on a if else statement within a method and I need it to send a message to the receiver with value of the argument from the method in the message. to clarify if the value of the argument is 1, I need to make the method send the message chicken1(). The code is below:

I have left the else part out as that is working fine. Also, this.chickens(); is my attempt to make this work but ive been working on this for ages and I cant seem to resolve the problem.

any help is very appreciated.

December 3rd, 2009, 02:42 AM

Json

Re: how to send a message to receiver with if else statement

I'm not really sure what you are trying to do to be honest. Do you want to pass the number of chickens on to some other method?

// Json

December 3rd, 2009, 11:33 AM

humdinger

Re: how to send a message to receiver with if else statement

No I dont need it to pass it on I just need it to send a message to the receiver with the value of the argument in the message. so if the value of the argument is 1 I need it to send a message to the receiver saying "chickens1()" and if the value of the argument is 2 it should be "chickens2" and so on.

Hi that looks like something that would work, however when i tried this the compiler came up with the error "cannot find symbol - method chickens(java.lang.string"

what I think this error is saying is that the compilere thinks chickens is a method??

hope someone can help me further. Thankyou for the help so far. I will be sure to thank everyone properly when the problem is resolved.

December 3rd, 2009, 03:17 PM

copeg

Re: how to send a message to receiver with if else statement

Yes, the compiler (as well as myself) thought chickens was a method, so in that case there should be a method like

Code :

public void chickens( String s ){
//do something
}

Of course whether or not there should be a chickens() method - and if so what it does - is dependent upon the behavior you want, and that I'm a bit unclear of so if you could describe what you want your code to do a bit further it may help

December 4th, 2009, 02:28 AM

Json

Re: how to send a message to receiver with if else statement

Yeah this is sort of what I meant, you could just put the number of chickens into the this.chickens method which would then print whatever message is needed.

// Json

December 4th, 2009, 07:27 AM

kyuss

Re: how to send a message to receiver with if else statement

Hi there, judging by humdingers other posts it looks like we're working on the same problem.

I have a couple of problems with it this. First off, when i try to run it I get the following error

Quote:

Semantic error: Message ( int ) not understood by class '

Could you throw some light on what's happening here? And the best methods for tacking the problem.

Many thanks for any advice you can give.

December 4th, 2009, 08:10 AM

Freaky Chris

Re: how to send a message to receiver with if else statement

Assuming that both face1() or whatever you decide to call it, and face2() etc all have the same medthod headers then this problem can be easily solved using Function objects, since Java doesn't support Function pointers.