Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import java.util.ArrayList; public class Shelter implements TestAnimals { privat

ID: 3708122 • Letter: I

Question

import java.util.ArrayList;
public class Shelter implements TestAnimals
{
   private ArrayList<Animal> myAnimal;
   static int numCats = 0;
   static int numDogs = 0;
   static int numReptiles = 0;
  
   public Animals()
   {
   myAnimal = new ArrayList<Animal>();
  
   }
   public void allAnimals()
   {
      for (Animal a1 : myAnimal)
      {
      System.out.println(a1);
      }
     }
     public boolean acceptAnimal(Animal new Animal)
     {
     boolean success = false;
     if (newAnimal instanceof Cat && numCats < CATSMAX)
     {
     Cat copyAnimal = new Cat((Cat) new Animal);
     myAnimal.add(copyAnimal);
     numCats++;
     success = true;
     }
     else (newAnimal instanceof Dog && numDogs < DOGSMAX)
     {
     myAnimal.add(newAnimal);
     numAnimal++;
     success = true;
     }
     else (newAnimal instanceof Reptile && numReptile < REPTILESMAX)
     {
     myAnimal.add(newAnimal);
     numAnimal++;
     success = true;
     }
     return success;
     }
    
     public boolean removeAnimal (int id)
     {
     boolean removed = false;
     for (int i = 0; i < myAnimal.size(); i++)
     {
     if (myAnimal.get(i).getId() == id) {
     if (myAnimal.get(i) instanceof Cat)
         numCats--;
     if (myAnimal.get(i) instanceof Dog)
         numDogs--;
            
     if (myAnimal.get(i) instanceof Reptile)
         numReptiles--;
  
      myAnimals.remove(i);
      removed = true;
      }
    }
   
    return removed;
   
    }
   
    public void allType(int animalType)
    {
    for (Animal a : myAnimal)
    {
    if (a instanceof Cat && AnimalType == 1)
      System.out.print(a);
      else (a instanceof Dog && AnimalType == 2)
      System.out.print(a);
      else (a instanceof Reptile && AnimalType == 3)
      System.out.print(a);
      }
     
    }
   
}

//////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////

Can you write the javadocs for this?

Explanation / Answer

import java.util.ArrayList; public class Shelter implements TestAnimals { private ArrayList myAnimal; static int numCats = 0; static int numDogs = 0; static int numReptiles = 0; /** * Constructor to initialize myAnimal ArrayList */ public Animals() { myAnimal = new ArrayList(); } /** * Prints animals in shelter. One animal per line. */ public void allAnimals() { for (Animal a1 : myAnimal) { System.out.println(a1); } } /** * Adds a new Animal to the shelter * * @return boolean to indicate when adding an animal to the shelter succeeded or not. */ public boolean acceptAnimal(Animal new Animal) { boolean success = false; if (newAnimal instanceof Cat && numCats