Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help cleaning up my code. When I submitted my assignment I got the following results: java.lang.NullPointerException What should happen getFirstAnimal public Animal getFirstAnimal()
I need help cleaning up my code. When I submitted my assignment I got the following results:
java.lang.NullPointerException
What should happen"
-
getFirstAnimal
public Animal getFirstAnimal()
Returns:
The first Animal in the array, or null if the array is empty
-
getLastAnimal
public Animal getLastAnimal()
This method will get the last Animal in the array
Returns:
Animal located at index numAnimals-1
My Code:
public Animal getFirstAnimal() { if(animals[0] == null) { return null; } else { return animals[0]; }
}
public Animal getLastAnimal() { return animals[getNumAnimals()-1]; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started