aj98

Untitled

Aug 31st, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1.  
  2. public class MyDate {
  3.  
  4. private int day;
  5. private int month;
  6. private int year;
  7.  
  8. public MyDate(int pv, int kk, int vv) {
  9. this.day = pv;
  10. this.month = kk;
  11. this.year = vv;
  12. }
  13.  
  14. public String toString() {
  15. return this.day + "." + this.month + "." + this.year;
  16. }
  17.  
  18. public boolean earlier(MyDate compared) {
  19. if (this.year < compared.year) {
  20. return true;
  21. }
  22.  
  23. if (this.year == compared.year && this.month < compared.month) {
  24. return true;
  25. }
  26.  
  27. if (this.year == compared.year && this.month == compared.month
  28. && this.day < compared.day) {
  29. return true;
  30. }
  31.  
  32. return false;
  33. }
  34.  
  35. /*
  36. * In assignment 92 method differneceInYears was added to MyDate
  37. * Copy the method here since it eases this assignment considerably.
  38. */
  39. public int differenceInYears(MyDate comparedDate) {
  40. int totalDays = this.day + (this.month * 30) + (this.year * 12 * 30);
  41. int totalDays2 = comparedDate.getDay() + (comparedDate.getMonth() * 30) + (comparedDate.getYear() * 12 * 30);
  42. int diffOfDays;
  43. if (totalDays > totalDays2) {
  44. diffOfDays = totalDays - totalDays2;
  45.  
  46. } else {
  47. diffOfDays = totalDays2 - totalDays;
  48. }
  49. // int diffOfDays = totalDays - totalDays2;
  50.  
  51. if (diffOfDays > 360) {
  52. int years = diffOfDays / 360;
  53. return years;
  54.  
  55. } else if (diffOfDays == 360) {
  56. return 1;
  57. } else {
  58. return 0;
  59. }
  60. }
  61.  
  62.  
  63. public int getDay() {
  64. return day;
  65. }
  66.  
  67. public int getMonth() {
  68. return month;
  69. }
  70.  
  71. public int getYear() {
  72. return year;
  73. }
  74.  
  75. }
Add Comment
Please, Sign In to add comment