Question: Adds a runner to the object array called arrayRunners. I want to make it so that if the object parameter (the runner) already exists in
Adds a runner to the object array called arrayRunners. I want to make it so that if the object parameter (the runner) already exists in the array it returns an error message which is below. My code does not work .... so
public void addRunner(Runner runner) {
int i;
for (i = 0; i < arrayRunners.length; i++) {
if (arrayRunners[i] == null && arrayRunners[i] != runner) {
arrayRunners[i] = runner;
break;
}
else {
System.out.println("The runner already exists");
//This prints when I run the method no matter what
}
}
}
Step by Step Solution
There are 3 Steps involved in it
The issue with your current implementation is that the condition in the if statement that checks for ... View full answer
Get step-by-step solutions from verified subject matter experts
