some code samples, various examples of simple modeling ideas and some minor algorithms.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. class Calendar extends Date
  2. {
  3. public Calendar(int d,int m,int y) throws DateException
  4. {
  5. super(d,m,y);
  6. }
  7. public void addDay()
  8. {
  9. day++;
  10. if(day==32)
  11. {
  12. day=1;
  13. month++;
  14. }
  15. else if(day==31&&(month==4||month==6||month==9||month==11))
  16. {
  17. day=1;
  18. month++;
  19. }
  20. else if(day==30&&month==2)
  21. {
  22. day=1;
  23. month=3;
  24. }
  25. else if(day==29&&month==2&&year%4!=0)
  26. {
  27. day=1;
  28. month=3;
  29. }
  30. if(month==13)
  31. {
  32. month=1;
  33. year++;
  34. }
  35. }
  36. public void subDay()
  37. {
  38. day--;
  39. if(day==0)
  40. {
  41. month--;
  42. if(month==0)
  43. {
  44. month=12;
  45. day=31;
  46. year--;
  47. }
  48. else if(month==4||month==6||month==9||month==11)
  49. day=30;
  50. else if(month==2)
  51. if(year%4==0)
  52. day=29;
  53. else
  54. day=28;
  55. else
  56. day=31;
  57. }
  58. }
  59. public void addMonth()
  60. {
  61. month++;
  62. if(month==13)
  63. {
  64. month=1;
  65. year++;
  66. }
  67. else if(day==31&&(month==4||month==6||month==9||month==11))
  68. day=30;
  69. else if(month==2)
  70. if(year%4==0)
  71. {
  72. if(day>29)
  73. day=29;
  74. }
  75. else if(day>28)
  76. day=28;
  77. }
  78. public void subMonth()
  79. {
  80. month--;
  81. if(month==0)
  82. {
  83. month=12;
  84. year--;
  85. }
  86. else if(day==31&&(month==4||month==6||month==9||month==11))
  87. day=30;
  88. else if(month==2)
  89. if(year%4==0)
  90. {
  91. if(day>29)
  92. day=29;
  93. }
  94. else if(day>28)
  95. day=28;
  96. }
  97. public void addYear()
  98. {
  99. year++;
  100. if(month==2&&day==29)
  101. day=28;
  102. }
  103. public void subYear()
  104. {
  105. year--;
  106. if(month==2&&day==29)
  107. day=28;
  108. }
  109. }