Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

135 righe
2.4 KiB

  1. /*
  2. * Written by : Bin Hong Lee
  3. * Last edited : 6/12/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 borrowBook(User user, Book book)
  16. {
  17. User newUser = user;
  18. if(book.getStatus() == "AVAILABLE" && newUser.status())
  19. {
  20. book.rent(calDueDate(10));
  21. newUser.borrowNewBook(book.getId());
  22. books.update(book);
  23. users.update(user, newUser);
  24. return true;
  25. }
  26. return false;
  27. }
  28. public static boolean returnBook(User user, Book book)
  29. {
  30. User newUser = user;
  31. if(newUser.returnBook(book.getId()))
  32. {
  33. book.returned();
  34. books.update(book);
  35. users.update(user, newUser);
  36. return true;
  37. }
  38. return false;
  39. }
  40. public static int[] calDueDate(int days)
  41. {
  42. int[] dueDate = currentDay();
  43. for (int i = 0; i < days; i++)
  44. {
  45. if(dueDate[2] < 28)
  46. {
  47. dueDate[2]++;
  48. }
  49. else if(dueDate[1] == 12)
  50. {
  51. if(dueDate[2] == 31)
  52. {
  53. dueDate[0]++;
  54. dueDate[1] = 1;
  55. dueDate[2] = 1;
  56. }
  57. }
  58. else if(dueDate[1] == 2)
  59. {
  60. if((dueDate[0] % 4) == 0)
  61. {
  62. if(dueDate[2] == 29)
  63. {
  64. dueDate[1]++;
  65. dueDate[2] = 1;
  66. }
  67. else
  68. {
  69. dueDate[2]++;
  70. }
  71. }
  72. else if(dueDate[2] == 28)
  73. {
  74. dueDate[1]++;
  75. dueDate[2] = 1;
  76. }
  77. else
  78. {
  79. dueDate[2]++;
  80. }
  81. }
  82. else if(dueDate[1] == 4 || dueDate[1] == 6 || dueDate[1] == 9 || dueDate[1] == 11)
  83. {
  84. if(dueDate[2] == 30)
  85. {
  86. dueDate[1]++;
  87. dueDate[2] = 1;
  88. }
  89. else
  90. {
  91. dueDate[2]++;
  92. }
  93. }
  94. else if(dueDate[2] == 31)
  95. {
  96. dueDate[1]++;
  97. dueDate[2] = 1;
  98. }
  99. else
  100. {
  101. dueDate[2]++;
  102. }
  103. }
  104. return dueDate;
  105. }
  106. public static int[] currentDay()
  107. {
  108. int[] currentDay = new int[3];
  109. currentDay[0] = date.getYear() + 1900;
  110. currentDay[1] = date.getMonth() + 1;
  111. currentDay[2] = date.getDate();
  112. return currentDay;
  113. }
  114. }