Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*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

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

*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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions