Advertisement
Guest User

Untitled

a guest
Sep 21st, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1.  
  2. public class MyDate904
  3. {
  4. private int day;
  5. private int month;
  6. private int year;
  7.  
  8.  
  9. public MyDate904(int day, int month, int year)
  10. {
  11. this.day = day;
  12. this.month = month;
  13. this.year = year;
  14. }
  15.  
  16. public MyDate904()
  17. {
  18. this.day = 3;
  19. this.month = 9;
  20. this.year = 14;
  21. }
  22.  
  23. public int getDay()
  24. {
  25. return day;
  26. }
  27. public void setDay(int d)
  28. {
  29. day = d;
  30. }
  31. public int getMonth()
  32. {
  33. return month;
  34. }
  35. public void setMonth(int m)
  36. {
  37. month = m;
  38. }
  39. public int getYear()
  40. {
  41. return year;
  42. }
  43. public void setYear(int y)
  44. {
  45. year = y;
  46. }
  47.  
  48. public String dayOfWeek ()
  49. {
  50. int q = day;
  51. int m;
  52.  
  53. int y = year;
  54. if(month==1)
  55. {
  56. m = 13;
  57. y = year-1;
  58. }
  59. else if(month==2)
  60. {
  61. m = 14;
  62. y = year-1;
  63. }
  64. else
  65. {
  66. m = month;
  67. }
  68. int k = y%100;
  69. int j = y/100;
  70. int h = ( q + ((13*(m + 1))/5) + k + (k / 4) + (j / 4) + 5*j)%7;
  71.  
  72. if(h==0)
  73. {
  74. return "Saturday";
  75. }
  76. else if(h==1)
  77. {
  78. return "Sunday";
  79. }
  80. else if(h==2)
  81. {
  82. return "Monday";
  83. }
  84. else if(h==3)
  85. {
  86. return "Tuesday";
  87. }
  88. else if(h==4)
  89. {
  90. return "Wednesday";
  91. }
  92. else if(h==5)
  93. {
  94. return "Thursday";
  95. }
  96. else if(h==6)
  97. {
  98. return "Friday";
  99. }
  100. else
  101. {
  102. return "Error";
  103. }
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement