Beruflich Dokumente
Kultur Dokumente
direction = NORTH;
else
direction = SOUTH;
stepsThisLeg = 1;
stepsSoFar = 0;
}
public int fight(String opponent){
int result;
if( Math.random() > 0.5 )
result = SCISSORS;
else
result = ROCK;
return result;
}
public Color getColor(){
return Color.ORANGE;
}
public String toString(){
return "B";
}
public int getMove(CritterInfo info){
if( stepsSoFar == stepsThisLeg){
stepsSoFar = 0;
stepsThisLeg++;
if( Math.random() > 0.5 )
direction = NORTH;
else
direction = SOUTH;
}
stepsSoFar++;
return direction;
}
}
criteria:
1 point, header. Lose this if does not include implements Critter
3 points, fields / instance variables (-2 if not private) (partial credit possib
le)
2 points, constructor. (could get tricky if getMove correct) (partial credit pos
sible)
2 points, fight (partial credit possible)
1 point, getColor
1 point, toString
5 points, getMove (partial credit possible)
7. Suggested Solution:
public static boolean oneDifferent(String s1, String s2){
// check if lengths different by 2 or more characters
if( Math.abs( s1.length() - s2.length() ) > 1 )
return false;
int smallestLength = Math.min( s1.length(), s2.length() );