Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. (XX points) Fill in the template below to make a complete class definition for a class that describes a pet adoption system. The system

image text in transcribed
image text in transcribed
image text in transcribed
2. (XX points) Fill in the template below to make a complete class definition for a class that describes a pet adoption system. The system is implemented using an ArrayLists of pet names called pets and a count of pets that are adopted called numAdopted. So that there will not be confusion when adopting the class's constructor and mutator methods MUST be implemented with the strings in the list pets must always be unique. Make sure your code conforms to the instructions given in the comments for each method. Note: You are also being asked to write the code for a private helper method named getIndexOfPet. Make sure you are using this method in your accessors and mutators where appropriate to receive full credit! You may use the ArrayList methods on the back page when solving this problem. public class PetAdoption System private ArrayList pets; 17 List of pets private int numAdopted; // Number of pets adopted public PetAdoption System { 17 Constructor that takes no parameters. The initial list 11 of pets must be empty and the numAdopted must be zero. private int getIndexOfPet(String petName) { 77 Helper method that takes a String as a parameter and if the String // is in the list pets returns its index in the list. Otherwise // returns a -1. public shelter // Mutator method that takes a pet name as parameter. Returns false // if the pet is already in the list, otherwise adds the pet to the // end of the pet list and returns true. public lookup 1/ Accessor method that takes a String as a pet and if it is // in the pets list returns true. If it is not in the // players list returns false. TODO public adopt ) // Mutator method that takes a pet name. Returns false if the pet It is not already in the list, otherwise removes the pet name from 1 pets, increments numAdopted, and returns true. public get. NumAdopted ( // Accessor method that takes no parameters. Returns the number of // animals that have been adopted

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_2

Step: 3

blur-text-image_3

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 Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions

Question

Explain walter's model of dividend policy.

Answered: 1 week ago

Question

=+j Describe how EU directives impact IHRM.

Answered: 1 week ago

Question

=+and reduction in force, and intellectual property.

Answered: 1 week ago