Question: not sure if I wrote the java method public Traveler findTravelerByName(String name) correctly please take a look and give any corrections you may see thank

not sure if I wrote the java method public Traveler findTravelerByName(String name) correctly please take a look and give any corrections you may see thank you:

public Traveler findTravelerByName(String name) 1. returns the Traveler with the given name 2. null if not found.

public class AvailableTravelers

{

private Traveler travelers[];

private int numOfTravelers;

public AvailableTravelers()

{

travelers = new Traveler[20];

this.numOfTravelers = 0;

}

public AvailableTravelers(int capacity)

{

travelers = new Traveler[capacity];

this.numOfTravelers = 0;

}

public boolean addTraveler(Traveler t)

{

if (numOfTravelers >= travelers.length)

return false;

for (int i=0; i

{

if(t.getId() == travelers[i].getId())

return false;

}

travelers[numOfTravelers ++] = t;

return true;

}

public Traveler findTravelerByName(String name)

{

for (int i = 0; i < numOfTravelers; i++)

{

if(name.equalsIgnoreCase(travelers[i].getName()))

{

return travelers[i];

}

}

return null;

}

public String toString()

{

String res = "";

for(int i = 0; i < numOfTravelers; i++)

{

res += travelers[i] + " ";

}

return res;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!