Wednesday, 2 October 2013

Adding a variable to an array

Adding a variable to an array

I'm having trouble writing this instance method.. I'm trying to write the
method so that the method will check if there is space for another
competitor. And if there is, another competitor will be added in the next
available slot.
public boolean addCompetitor(Competitor competitor) {
// TODO
for(int i=0;i<competitors.length; i++){
if(numberOfCompetitors < MAX_COMPETITORS){
numberOfCompetitors++;
return true;
}
}
return false;
}
I've done a loop to see if I can just add the variable to the array if the
conditions met true.

No comments:

Post a Comment