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...

1 answer below »

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





Answered Same DaySep 08, 2021

Answer To: Learning objective: Review basic Java class and object constructs. To include writing classes with...

Ramachandran answered on Sep 08 2021
144 Votes
Order-90803/Animal.java
Order-90803/Animal.java
public class Animal {
    private String name;
    private AnimalTy
pe type;
    private int age;
    private boolean isTrained;
    public Animal() {
    }
    public Animal(String name, AnimalType type) {
        this.name = name;
        this.type = type;
    }
    public Animal(String name, AnimalType type, int age, boolean isTrained) {
        this.name = name;
        this.type = type;
        this.age = age;
        this.isTrained = isTrained;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public AnimalType getType() {
        return type;
    }
    public void setType(AnimalType type) {
        this.type = type;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public boolean isTrained() {
        return isTrained;
    }
    public void setTrained(boolean trained) {
        isTrained = trained;
    }
    @Override
    public String toString() {
        String message = "the pet's name is %s the pet's age is ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here