CymsSoul

Untitled

Dec 27th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. import java.util.Calendar;
  2.  
  3. public class Person {
  4. private String name;
  5. private MyDate birthday;
  6.  
  7. public Person(String name, int pp, int kk, int vv) {
  8. this.name = name;
  9. this.birthday = new MyDate(pp, kk, vv);
  10. }
  11.  
  12. public Person(String name, MyDate birthday)
  13. {
  14. this.name = name;
  15. this.birthday = birthday;
  16. }
  17.  
  18. public Person(String name)
  19. {
  20. int day = Calendar.getInstance().get(Calendar.DATE);
  21. int month = Calendar.getInstance().get(Calendar.MONTH) + 1; // January is 0 so we add one
  22. int year = Calendar.getInstance().get(Calendar.YEAR);
  23. this.name = name;
  24. this.birthday = new MyDate(day, month, year);;
  25. }
  26.  
  27.  
  28. public int age() {
  29. // calculate the age based on the birthday and the current day
  30. // you get the current day as follows:
  31. int day = Calendar.getInstance().get(Calendar.DATE);
  32. int month = Calendar.getInstance().get(Calendar.MONTH) + 1; // January is 0 so we add one
  33. int year = Calendar.getInstance().get(Calendar.YEAR);
  34.  
  35. MyDate currentDate = new MyDate(day, month, year);
  36.  
  37. return currentDate.differneceInYears(birthday);
  38. }
  39.  
  40. public boolean olderThan(Person compared) {
  41. // compare the ages based on birthdays
  42.  
  43. return this.age() > compared.age();
  44. }
  45.  
  46. public String getName() {
  47. return this.name;
  48. }
  49.  
  50. public String toString() {
  51. return this.name + ", born " + this.birthday;
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment