Method calls with arrays (origionally posted in wrong place)
sry i had origionally posted this in the java developers section of the forum
alright i was wondineg if it is possible to call methods with an array
here is why i need this to happen:
i am calling a series of methods that all have the same return time (boolean)
and once the return from one of these method becomes true i need to stop and return that
a "driver" is calling all of these methods
(it's a poker game)
it first calls isRoyalFlush....then all the way down to isHighCard
i realize that they dont' truly have to be seperate methods, but for testing/creating it would be much easier. once they return a true value, i want the search to break and return
could anyboyd tell me how to, or an alternate way to doing this?
if that makes no sense:
public void Play()
{
Method[]arr=new Method[/*not sure what goes here*/]; /*maybe like the method names, i'm thinking of somethign like an onClick in javascript for buttons where i would do onClick="isRoyalFlush()"*/
boolean isType=false;
for(int i=0;i<9;i++)
{
isType=arr[i];
if(isType)
//print and do all that stuff
}
}
public boolean isRoyalFlush()//this would be cell 0 in the array
{
}
public boolean isStraightFlush()//cell 1....etc
{
}
Using reflection here would be overkill, i think.
..but you could have solved the problem using those methods. I your case
I would have done something like this:
Code:
public class Poker {
public final static int ROYAL_STRAIGHT_FLUSH=9;
public final static int STRAIGHT_FLUSH=8;
// etc. etc.
public final static int HI_CARD=0;
public int getHand() {
int handType;
for (handType=ROYAL_STRAIGHT_FLUSH; handType>=HI_CARD; handType--) {
switch (handType) {
case ROYAL_STRAIGHT_FLUSH:
if (isRoyalFlush()) return handType;
break;
case STRAIGHT_FLUSH:
if (isStraightFlush()) return handType;
break;
// etc. etc.
}
}
}
}