Advertisement
Radoslav_03

1vi file

Nov 6th, 2023
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. import java.io.Serializable;
  2. import java.time.LocalDate;
  3.  
  4. public class Person implements Serializable{
  5.     private final String name;
  6.     private final LocalDate birth;
  7.     private int age;
  8.  
  9.     public Person(String name, LocalDate birth){
  10.         this.name = name;
  11.         this.birth = birth;
  12.         recalculateAge();
  13.     }
  14.  
  15.     public String getName(){
  16.         return name;
  17.     }
  18.  
  19.     public LocalDate getBirth(){
  20.         return birth;
  21.     }
  22.  
  23.     public int getAge(){
  24.         return age;
  25.     }
  26.  
  27.     private void recalculateAge() {
  28.         age = LocalDate.now().getYear() - birth.getYear();
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement