Problem with else/if statement

Though the for-loop problem has already been fixed, there is a problem with my model not calculating the happyRatio and hence stopping the step method when its conditions have been satisfied. Why is happyRatio and the else/if statement right before it not working? The debug statement "I'M FINALLY FREAKING WORKING NOW..." isn't working. And hasn't. For a long. long. time. Argh.

publicvoid step (){

System.out.printf("==> Swimmer step beginning" );

int moved = 0;// Has not yet moved this step

Vector swimmerNeighbors =new Vector();

Vector badNeighbors =new Vector();

System.out.printf("==> created variables in the step method");

vector = world.getMooreNeighbors(x, y,false);

//System.out.println(vector);

for (int i = 0; i < vector.size(); i++ ){

Object o = vector.get(i);

if (oinstanceof Swimmer){

swimmerNeighbors.add(o);

System.out.printf("==> swimmers getting added to list now");

}

elseif (oinstanceof Surfer){

badNeighbors.add(o);

System.out.printf("==> I'M FINALLY FREAKING WORKING NOW...);

}

}

//Is the Swimmer happy? ( >= 50% similarity)

//Empty and similar count as happy; dissimilar counts as unhappy;

double happyRatio = (8.0 - badNeighbors.size())/8.0;

if ( happyRatio > 0.5 ){//The Swimmer is happy; they end their move

System.out.printf("-- is happy right here!");

}

// Otherwise, the Swimmer is unhappy; they seek to move

[2579 byte] By [tarahmariea] at [2007-10-2 1:47:15]
# 1
Please give us the exact code with the problem.To do this, simply copy/paste within the code tags.The code you are showing dows not even compile, so is impossible to execute (clearly).
jfbrierea at 2007-7-15 19:28:25 > top of Java-index,Java Essentials,New To Java...
# 2
Why did you start a new thread? Can't you continue on this in your previous thread? http://forum.java.sun.com/thread.jspa?threadID=670422
MLRona at 2007-7-15 19:28:25 > top of Java-index,Java Essentials,New To Java...
# 3

YOu need to debug. And also introduce an else statement:

if (o instanceof Swimmer){

swimmerNeighbors.add(o);

System.out.printf("==> swimmers getting added to list now");

}

else if (o instanceof Surfer){

badNeighbors.add(o);

System.out.printf("==> I'M FINALLY FREAKING WORKING NOW...);

} else {

System.out.println("I haven't thought of that: "+o.getClass().getName());

}

MartinHilperta at 2007-7-15 19:28:25 > top of Java-index,Java Essentials,New To Java...