Classes and Objects
- Accept the Lab2-OOP (Link is on Canvas)
- Clone the repository
- Open the project in IntelliJ
- Modify the empty
Person
class in accordance to the class description below. - create an
ageValidation
Method that throws anExceptionInInitializerError
exception when the YOB is less than 1900.- Use this method in both the constructor and the
setYOB
methods.
- Use this method in both the constructor and the
- You are done with this lab if you pass all the tests in
PersonTest
- we will be learning about unit tests later in the class 😉 🌟
Person Class
Person | Â | Â |
---|---|---|
Fields | Â | Â |
 | String firstName; |  |
 | String lastName; |  |
 | int YOB; | - Year of Birth - Range should be 1900-2010 - make sure validations happen in the constructor as well as the setter method. |
Methods | Â | Â |
 | Constructor | - 2 constructors; one that takes first and last name, and the other takes the same plus the YOB |
 | Getters and Setters |  |
 | public String fullName() | returns a concatenation of the first and last names |
 | public static int calculateAge(int year) | - A static method that takes a year and returns an age. - Use the Calendar Object to get current Year (may requires a bit of web search) |
 | public int getAge() | - gets the age of the person object. - Use the calculateAge() method for this |