Method returning null Class

Multi tool use


Method returning null Class
I think maybe this could be a design problem but I have a problem with a method that should return a specific class that is passed in the method. However, the method should return the modified class but it returns null.
AnimalSummary animalSummary = new AnimalSummary()
for (animal : animals){
animalSummary = new Zoo().calculateAnimalTypeLegs(animal, animalSummary)
}
This is the method
AnimalSummary calculateAnimalTypeLegs(Animal animal, AnimalSummary animalSummary){
if (animal.type.equals("Bear")
animalSummary.setTotalLegs(animalSummary.getTotalLegs()+4)
if (animal.type.equals("Human")
animalSummary.setTotalLegs(animalSummary.getTotalLegs()+2)
return animalSummary
While iterating through all the elements the first class is initialized correctly, but after the first return of the method and the second element the class animalSummary is null.
While debugging the first time the method gets the animalSummary class is correctly initialized. However it is after returning the value and entering in the second iteration that the animalSummary class is null
Our God of Programming Debuger what say?
– raul1ro
3 mins ago
what exactly are you trying to get
– dangi13
3 mins ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
where you create animalSummary. give more code
– sajib
3 mins ago