Advertisement
Parasect

y

Sep 9th, 2014
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. package dateproj;
  2.  
  3.  
  4. public class DateProj
  5. {
  6. private static Date d=new Date(28,2,2001);
  7. private static Date y=new Date(23,9,98);
  8.  
  9. public static void main(String[] args)
  10. {
  11. System.out.println(d.compareTo(y));
  12. Date m = d.getTomorrow();
  13. System.out.println(m.toString());
  14. int x= 6;
  15. Date z = new Date(1,9,2014);
  16. for(int i = 0; i<x; i++){
  17. z = z.getTomorrow();
  18. }
  19. System.out.println(z.toString());
  20.  
  21. }
  22. private boolean isLeapYear(){
  23. if(d.getYear()%4==0)
  24. return true;
  25. return false;
  26. }
  27. }
  28. ------------------------------------------------------------
  29. package dateproj;
  30.  
  31. import java.util.Calendar;
  32. import java.util.GregorianCalendar;
  33.  
  34. /**
  35. * Document : yoyo Created on : 08/09/2014, 12:49:47 Author : Admin
  36. */
  37. public class Date
  38. {
  39. private int dd;
  40. private int mm;
  41. private int yy;
  42.  
  43. public Date(int day, int month, int year)
  44. {
  45. dd = day;
  46. mm = month;
  47. yy = year;
  48. }
  49.  
  50. public int getYear()
  51. {
  52. return yy;
  53. }
  54.  
  55. public int getMonth()
  56. {
  57. return mm;
  58. }
  59.  
  60. public int getDay()
  61. {
  62. return dd;
  63. }
  64.  
  65. public void setYear(int yearToSet)
  66. {
  67. yy = yearToSet;
  68. }
  69.  
  70. public void setMonth(int yearToSet)
  71. {
  72. mm = yearToSet;
  73. }
  74.  
  75. public void setDay(int yearToSet)
  76. {
  77. dd = yearToSet;
  78. }
  79.  
  80. public int compareTo(Date other)
  81. {
  82. if((yy > other.yy) || (mm > other.mm && yy == other.yy) || (dd > other.dd && mm == other.mm && yy >= other.yy))
  83. {
  84. return 1;
  85. }
  86. if((yy < other.yy) || (mm < other.mm && yy == other.yy) || (dd < other.dd && mm <= other.mm && yy <= other.yy))
  87. {
  88. return -1;
  89. }
  90. return 0;
  91. }
  92.  
  93. public String toString()
  94. {
  95. return ("<" + dd + "><" + mm + "><" + yy + ">");
  96. }
  97.  
  98. public Date getTomorrow()
  99. {
  100. int x = dd + 1;
  101. int y = mm;
  102. int z = yy;
  103.  
  104. if(dd == 31
  105. || (dd == 30 && mm % 2 == 0)
  106. || (yy % 4 == 0 && mm == 2 && dd == 29)
  107. || (mm == 2 && dd == 28 && yy % 4 != 0))
  108. {
  109. y++;
  110. x = 1;
  111. }
  112. if(mm == 13)
  113. {
  114. z++;
  115. y = 1;
  116. }
  117.  
  118. Date n = new Date(x, y, z);
  119. return n;
  120. }
  121.  
  122. public void setCurrent(){
  123. GregorianCalendar n = new GregorianCalendar();
  124. dd = n.get(Calendar.DAY_OF_MONTH);
  125. mm = n.get(Calendar.MONTH);
  126. yy = n.get(Calendar.YEAR);
  127.  
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement