Classes and Objects
- Accept the Lab2-OOP (Link is on Canvas)
- Clone the repository
- Open the project in IntelliJ
- Modify the empty
Personclass in accordance to the class description below. - create an
ageValidationMethod that throws anExceptionInInitializerErrorexception when the YOB is less than 1900.- Use this method in both the constructor and the
setYOBmethods.
- 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 |