Created
April 11, 2019 08:57
-
-
Save sokratis12GR/a9f8abaed15c8449cedfe4bebf7974b7 to your computer and use it in GitHub Desktop.
How to get the age, and set stuff for people... will need for future projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
import java.time.LocalDate; | |
import java.util.Date; | |
import java.util.Random; | |
public class Person { | |
Random rand = new Random(); | |
private int age; | |
private boolean isAdult; | |
public Person(byte day, byte month, int year) { | |
this.age = LocalDate.now().minusYears(year).minusMonths(month).minusDays(day).getYear(); | |
} | |
public Person(int age) { | |
this.age = age; | |
this.isAdult = age >= 18; | |
} | |
public int getAge() { | |
return age; | |
} | |
public enum STAGE { | |
ADULT, | |
KID | |
} | |
public enum Sex { | |
MALE, | |
FEMALE | |
} | |
public static Person createNothing() { | |
return new Person(-1); | |
} | |
public static Person create(int age) { | |
return new Person(age); | |
} | |
public static Person create(byte day, byte month, int year) { | |
return new Person(day, month, year); | |
} | |
public static void main(String[] args) { | |
System.out.println(Person.create((byte) 14, (byte) 9, 2001).getAge()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment