I'm practicing using encapsulation in java to create an Employees profile. I'm trying to include both the employees age - calculated using
private Period age;
private LocalDate currentDate;
private LocalDate dob;
public Period calcAge() {
currentDate = LocalDate.now();
age = Period.between(currentDate, dob); //dob is Date Of Birth
return age;
}
, and the age at which they were hired. My first thoughts were to accomplish this with the following method:
public Period hiredAge() {
return Period.between(age, hireDate);
}
However, I receive the error "Period cannot be converted to LocalDate"
I've tried to research both a way to perform the calculation using "age" as a LocalDate - and by inputting hireDate as a Period, both to no avail. How can I calculate the age at which the Employee was hired?