Question: Please answer correctly in JAVA. Create a Pet class. Your class must use encapsulation (information hiding). Your Pet class is not a program. The state
Please answer correctly in JAVA.
Create a Pet class. Your class must use encapsulation (information hiding). Your Pet class is not a program. The state and behaviour of the class (and objects) is described as follows: A Pet object will have the following attributes: a name (String), birth year (int), type of pet (String such as cat, dog, eel), and a list of its children (array of Pet objects). Each attribute should have a getter method. Provide a setter method only for the list of children (that should take an entire array of Pet objects as input). The birth year must be a constant (i.e., once it is set it must never be changed). Provide a constructor that takes a name, birth year and type of animal as input and initializes the Pet object. The birth year can be given as 1-digit number (2, 4), a 2-digit number (12, 17, 99, etc) or a 4-digit number. You will store each birth year as a 4-digit number though. For example, 2 means 2002, 13 means 2013 and 1978 means 1978. We wont consider the complicating issues of very old pets.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
