Adds a runner to the object array called arrayRunners. I want to make it so that if
Fantastic news! We've Found the answer you've been seeking!
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 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
}
}
}
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date: