You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

117 lines
2.0 KiB

  1. /*
  2. * Written by : Bin Hong Lee
  3. * Last edited : 5/31/2016
  4. */
  5. import java.util.Date;
  6. class Main
  7. {
  8. Exception BookNotFound = new Exception("Error 404 : Book not found");
  9. static BookFactory books = new BookFactory();
  10. static UserFactory users = new UserFactory();
  11. static Date date = new Date();
  12. public static void main(String[] args)
  13. {
  14. }
  15. public static boolean returnBook(User user, Book book)
  16. {
  17. User newUser = user;
  18. if(newUser.returnBook(book.getId()))
  19. {
  20. book.returned();
  21. books.update(book);
  22. users.update(user, newUser);
  23. return true;
  24. }
  25. return false;
  26. }
  27. public static int[] calDueDate(int days)
  28. {
  29. int[] dueDate = currentDay();
  30. for (int i = 0; i < days; i++)
  31. {
  32. if(dueDate[2] < 28)
  33. {
  34. dueDate[2]++;
  35. }
  36. else if(dueDate[1] == 12)
  37. {
  38. if(dueDate[2] == 31)
  39. {
  40. dueDate[0]++;
  41. dueDate[1] = 1;
  42. dueDate[2] = 1;
  43. }
  44. }
  45. else if(dueDate[1] == 2)
  46. {
  47. if((dueDate[0] % 4) == 0)
  48. {
  49. if(dueDate[2] == 29)
  50. {
  51. dueDate[1]++;
  52. dueDate[2] = 1;
  53. }
  54. else
  55. {
  56. dueDate[2]++;
  57. }
  58. }
  59. else if(dueDate[2] == 28)
  60. {
  61. dueDate[1]++;
  62. dueDate[2] = 1;
  63. }
  64. else
  65. {
  66. dueDate[2]++;
  67. }
  68. }
  69. else if(dueDate[1] == 4 || dueDate[1] == 6 || dueDate[1] == 9 || dueDate[1] == 11)
  70. {
  71. if(dueDate[2] == 30)
  72. {
  73. dueDate[1]++;
  74. dueDate[2] = 1;
  75. }
  76. else
  77. {
  78. dueDate[2]++;
  79. }
  80. }
  81. else if(dueDate[2] == 31)
  82. {
  83. dueDate[1]++;
  84. dueDate[2] = 1;
  85. }
  86. else
  87. {
  88. dueDate[2]++;
  89. }
  90. }
  91. return dueDate;
  92. }
  93. public static int[] currentDay()
  94. {
  95. int[] currentDay = new int[3];
  96. currentDay[0] = date.getYear() + 1900;
  97. currentDay[1] = date.getMonth() + 1;
  98. currentDay[2] = date.getDate();
  99. return currentDay;
  100. }
  101. }