Question: Write a java code Task 1: Create a class Pet in Pet.java that contains a default constructor, a parameter constructor and getters and setters and
Write a java code
Task 1: Create a class Pet in Pet.java that contains a default constructor, a parameter constructor and getters and setters and a toString method. Class members are pet id, name, age, weight, an arraylist of names of previous owners and a Boolean of adopted or not (initially set as false in constructor).
Task 2: Add a method to Pet.java called adopt(), which asks user for their name, adding it to list of previous owners, and changing adopted to true.
Task 3: In Main.java, create an array of pets and add 5 pets to it
Task 4:write a function displayPets(Pet[] petArray) which takes in the pets array and first prints out adopted pets and then unadopted pets
Task 5: Call adopt() function on the first 2 pets, and then pass the pet list to displayPets(Pet[] petArray) method to display all pets.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
