Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

80 рядки
1.2 KiB

  1. class Book
  2. {
  3. private String title;
  4. private int id;
  5. //( AVAILABLE || RENTED || RESERVED || NOT AVAILABLE)
  6. private String status;
  7. private int[] dueDate = new int[3];
  8. public Book(int id, String status)
  9. {
  10. this.id = id;
  11. this.status = status;
  12. }
  13. public Book(String title, int id, String status)
  14. {
  15. this.title = title;
  16. this.id = id;
  17. this.status = status;
  18. }
  19. public String getTitle()
  20. {
  21. if (title!=null)
  22. {
  23. return title;
  24. } else {
  25. return "UNDEFINED";
  26. }
  27. }
  28. public String getStatus()
  29. {
  30. return status;
  31. }
  32. public boolean rent(int[] dueDate)
  33. {
  34. if(status != "AVAILABLE")
  35. {
  36. return false;
  37. }
  38. this.dueDate = dueDate;
  39. status = "RENTED";
  40. return true;
  41. }
  42. public void returned()
  43. {
  44. status = "AVAILABLE";
  45. }
  46. public double overdueFine(int[] currentDay)
  47. {
  48. double fine;
  49. if(currentDay[0] > dueDate[0] || currentDay[1] > (dueDate[1] + 1))
  50. {
  51. return 5;
  52. }
  53. else if(currentDay[1] > dueDate[1])
  54. {
  55. fine = (double)(currentDay[2] + 30 - dueDate[2]) * 0.25;
  56. }
  57. else
  58. {
  59. fine = (double)(currentDay[2] - dueDate[2]) * 0.25;
  60. }
  61. if(fine > 5)
  62. {
  63. return 5;
  64. }
  65. else
  66. {
  67. return fine;
  68. }
  69. }
  70. }