Question: *JAVA* Complete all implementation along with methods 1. This question involves managing the costs associated with animal adoption at an animal shelter. Animals are defined

 *JAVA* Complete all implementation along with methods 1. This question involves

managing the costs associated with animal adoption at an animal shelter. Animals

are defined by the following Animal class. public class Animal { /**

Constructs an Animal object with name n, type t, age a, and

*JAVA*

Complete all implementation along with methods

1. This question involves managing the costs associated with animal adoption at an animal shelter. Animals are defined by the following Animal class. public class Animal { /** Constructs an Animal object with name n, type t, age a, and cost c */ public Animal(String n, String t, double a, int c) { /* implementation not shown */ } /** Returns the type of the animal (for example, "dog" or "cat") */ public String getType() { /* implementation not shown */ } /** Returns the age of the animal when it arrived at the shelter, in years */ public double getAge() { /* implementation not shown */ } /** Returns the cost, in dollars, of adopting the animal */ public int getCost() { /* implementation not shown */ } // There may be instance variables, constructors, and methods that are not shown. } Information about an animal shelter is stored in an AnimalShelter object, which contains a list of the animals at the shelter. You will write two methods of the AnimalShelter class. public class AnimalShelter { /** A list of animals at the shelter, sorted by the age of the animal when it arrived at the shelter, from least to greatest Guaranteed not to be null and to contain only non-null entries */ private ArrayList allAnimals; * * /** Creates and returns a new Animal object, as described in part (a) */ private Animal createNewAnimal (String name, String type, double age) { /* to be implemented in part (a) */ } /** Adds an animal to the list allAnimals, as described in part (b) */ public void addAnimal(String name, String type, double age) { /* to be implemented in part (b) */ } // There may be instance variables, constructors, and methods that are not shown. } (a) Write the AnimalShelter method createNewAnimal. The method creates and returns a new Animal object. The animal's name is given by the name parameter, the animal's type is given by the type parameter, and the animal's age when it enters the shelter is given by the age parameter. As animals come into the shelter, the adoption cost, in dollars, is determined by the age of the animal and the number of animals of the same type, according to the following rules. If the age of the animal is less than one year and the shelter has fewer than 5 animals with the given type, the cost is $25. If the age of the animal is less than one year and the shelter has 5 or more animals with the given type, the cost is $20. Otherwise, the cost is $15. Complete method createNewAnimal. /** Creates and returns a new Animal object, as described in part (a) */ private Animal createNewAnimal(String name, String type, double age) (b) Write the AnimalShelter method addAnimal. The method creates a new Animal object with name name, type type, age age, and the adoption cost calculated in part (a). The new animal is added to the ArrayList allAnimals so that the sorted order of the list is maintained. The list is ordered by animal age, from least to greatest. Assume that createNewAnimal works as specified, regardless of what you wrote for part (a). You must use createNewAnimal appropriately to receive full credit. Complete method addAnimal. /** Adds an animal to the list allAnimals, as described in part (b) */ public void addAnimal(String name, String type, double age)

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!