Question
4. (40 pts) Create an AnimalBag class using an Animal array to store both Dog and Cat objects. Write the following methods: a. public void
4. (40 pts) Create an AnimalBag class using an Animal array to store both Dog and Cat objects. Write the following methods: a. public void insert(Animal animal) b. public void display() c. public Animal[] searchByName (String name) d. public Animal[] serschByWeight (double weight) e. public Animal removeByName (String name) f. public Animal[] removeByWeight (double weight) Write a Demo class to show you can insert the following two Dog objects and two Cat objects into an AnimalBag: Dog1s name and weight are D1 and 10 lbs., respectively. Dog2s name and weight are D2 and 20 lbs., respectively. Cat1s name and weight are called C1 and 5 lbs., respectively, and Cat2s name and weight are C2 and 10 lbs., respectively. Demonstrate your searchByName and searchByWeight, removeByName, and removeByWeight methods work. 5. (10 pts) Write an interface called Searchable. The interface should have the following unimplemented method: a. Animal[] search(Predicate predicate); Modify the AnimalBag class so it implements the Searchable interface. 6. (20 pts) Copy the Demo class you wrote in Problem 4 and demonstrate that the new search method in the AnimalBag class can be used to search a dog or a cat by name as well as by weight.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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