|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import java.time.LocalDate;
- import java.time.Period;
-
- public class Geburtstag {
- String name;
- int jahr;
- int monat;
- int tag;
- LocalDate datum;
-
- public Geburtstag(LocalDate datum) {
- this.datum = datum;
- }
-
- public Geburtstag(String name, int jahr, int monat, int tag) {
- this.name = name;
- this.datum = LocalDate.of(jahr, monat, tag);
- }
-
- public LocalDate naechsteGeburtstagsfeier() {
- Geburtstag temp = new Geburtstag(this.datum);
- LocalDate today = LocalDate.now();
- if (temp.datum.isAfter(today) || temp.datum.isEqual(today)) {
- // do nothing, birthday wasn't already or is today
- } else if (temp.datum.isBefore(today)) {
- for (int i = 0; temp.datum.isBefore(today) && !temp.datum.isEqual(today); i++) {
- temp.datum = temp.datum.plusYears(1);
- }
- }
- return temp.datum;
- }
-
- public int alter() {
- LocalDate today = LocalDate.now();
- int years = 0;
- try {
- years = Period.between(this.datum, today).getYears();
- if (this.datum.isEqual(today)) {
- years++;
- }
- } catch (Exception NullPointerException) {
- // date was invalid, do nothing
- }
- return years;
- }
- }
-
-
-
|