modified the updatePet(Pet newPet) method in Owner class

This commit is contained in:
Soumen Mallick 2025-01-01 09:34:40 +05:30
parent 98e5c6e28b
commit 9b582edb67
2 changed files with 7 additions and 8 deletions

View file

@ -174,14 +174,13 @@ public class Owner extends Person {
public void updatePet(Pet newPet)
{
for(int i=0 ; i<pets.size() ; i++)
Pet existingPet = getPet(newPet.getId());
if(existingPet != null)
{
Pet existingPet = pets.get(i);
if(existingPet.getId().equals(newPet.getId()))
{
pets.set(i,newPet);
break;
}
existingPet.setName(newPet.getName());
existingPet.setBirthDate(newPet.getBirthDate());
existingPet.setType(newPet.getType());
}
}