1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146.
|
class MyDate { int _day; int _month; int _year;
/** * Constructs a date. * * @param day the day. * @param month the month. * @param year the year. */ public MyDate(int day, int month, int year) { setDay(day); setMonth(month); setYear(year); } /** * Determines if a given (day, month, year) represents a valid date. * * @param day the day. * @param month the month. * @param year the year. * @return true if (day, month, year) represents a valid date, false else */ public static boolean isValidDate(int day, int month, int year) { return checkData(day, month, year); }
/** * Determines if a given (day, month, year) represents a valid date. * * @param day the day. * @param month the month. * @param year the year. * @return true if (day, month, year) represents a valid date, false else */ private static boolean checkData(int day, int month, int year) { return checkDay(day) && checkMonth(month) && checkYear(year) && checkDayLimits(day, month, year); }
/** * Determines if this object represents a valid date. * * @return true if this object represents a valid date, false else */ public boolean checkData() { return checkData(_day, _month, _year); }
/** * Get the last day given a month and a year. * * @param month the month. * @param year the year. * @return the last day of (month, year), (should be 28, 29, 30 or 31) */ public static int maxDayOfMonth(int month, int year) { int result = 31; if ( month == 2 ) result = ( year%4 == 0 ) ? 29 : 28; if ( month == 4 || month == 6 || month == 9 || month == 11 ) result = 30; return result; }
public static int maxDayOfMonth(int month) { return maxDayOfMonth(month, 2001); }
/** * Updates the day, month and year) attributes of this object * to the next day (tomorrow). * * @return this (my)date */ public MyDate nextDay() { // TODO return this; } /** * Allocates a <code>MyDate</code> object and initializes it to represent * the day (tomorrow) which follows the provided day, month and year. * * @param day the day. * @param month the month. * @param year the year. * @return a (my)date object initialized to next day of (day, month, year) */ public static MyDate nextDay(int day, int month, int year) { MyDate date = new MyDate(day, month, year); return date.nextDay(); } private static boolean checkDayLimits(int day, int month, int year) { if ( month == 2 ) return checkFebruaryDayLimits(day, year); // TODO Auto-generated method stub return true; }
private static boolean checkFebruaryDayLimits(int day, int year) { // TODO Auto-generated method stub return true; }
private static boolean checkDay(int day) { return day >= 0 && day < 32; }
private static boolean checkMonth(int month) { return month > 0 && month < 13; }
private static boolean checkYear(int year) { return true; }
public int getYear() { return _year; }
private void setYear(int _year) { this._year = _year; }
public int getDay() { return _day; }
private void setDay(int _jour) { this._day = _jour; }
public int getMonth() { return _month; }
private void setMonth(int _month) { this._month = _month; }
}
|