Question: Java: Question 1: Question 2: Implement an immutable class called Animal with the following attributes: type (String value) and age (int value). Implement a custom

Java:

Question 1:

Java: Question 1: Question 2: Implement an immutable class called Animal withQuestion 2:

the following attributes: type (String value) and age (int value). Implement a

Implement an immutable class called Animal with the following attributes: type (String value) and age (int value). Implement a custom checked exception class for InvalidAgeException. This exception is thrown when there is an attempt to set an invalid age range for an instance of class Person. Below is the implementation of class Person that would use this exception. public class Person { private String firstName; private String lastName; private int age; // constructor: Person(String fn, String in, int age) { this.firstName = fn; this. lastName = ln; this.age = age; } // getters: public String getFirstName() {return this.firstName;} public String getLastName() {return this. lastName;} public int getAge() {return this.age;} // setters: public void setFirstName (String fn){this.firstName = fn;} public void setLastName (String In){this. lastName = ln;} public void setAge(int age) { if(age 120){ throw new InvalidAgeException ("The age is outside allowed range."); }else{ this. age = age; } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!