Learning objective: Review basic Java class and object constructs. To include writing classes with attributes, constructors and methods. Demonstrate an example of encapsulation, using an array of objects, and overloading a constructor.
For this assignment, you will be creating a list of animals in the shelter that someone could adopt using a class structure and an array. Depending on whether the user wants a cat or a dog, you will display the animals they can choose from. The following provides the specific guidance for the assignment. There is also a rubric that will be used for grading.
1) Create a class for animals in a shelter to include attributes for name (string), type (cat, dog), age (int), and training (yes or no).
2) Demonstrate encapsulation of the animal name with appropriate access specifier and provide a “setter” and “getter”
3) Overload toString to display descriptions in a nicely formatted output.
4) In addition to writing a default constructor, define two overloaded constructors. The first one should accept and initialize the name and type. The second one should initialize all the class data.
5) When using the default constructor, demonstrate setting the name attributes with the setter from the main program to set values.
6) In the main program, use an array to store at least 6 animal objects with a mix of dog and cat types.
7) Create at least 6 objects and make sure to create some with the default constructor and some using both overloaded constructors.
8) Provide a user interface that asks whether the user wants to adopt a cat or dog and then displays the list of available animals and their characteristics based on their input.
Submit your file(s) and execution screenshots showing the user display. Demonstrate both cat and dog user options. Just a reminder, that the code must be your own original work.
The following provides an example of one possible output (yours does not have to look exactly like this, just needs to have the required content);
Hello and welcome to the Animal Shelter.
Are you interested in adopting a cat? If so enter true, if not enter false.
true
Here is the list of cats for adoption.
the pets name is Fluffythe pet's age is 5the pet is not trained
the pets name is Kittythe pet's age is 1the pet is not trained
the pets name is Milothe pet's age is 8the pet is trained
Hello and welcome to the Animal Shelter.
Are you interested in adopting a cat? If so enter true, if not enter false.
false
Here is a list of dogs for adoption.
the pets name is Fritzthe pet's age is 3the pet is not trained
the pets name is Maxthe pet's age is 2the pet is trained
the pets name is Fidothe pet's age is 10the pet is trained