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

1 Expert Approved Answer
Step: 1 Unlock

The issue with your current implementation is that the condition in the if statement that checks for ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!