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.
 
 

110 lines
1.8 KiB

  1. /*
  2. * Written by : Bin Hong Lee
  3. * Last edited : 4/27/2016
  4. */
  5. class Book
  6. {
  7. //Declaring variable storages
  8. //Book title
  9. private String title;
  10. //Book ID
  11. private int id;
  12. //( AVAILABLE || RENTED || RESERVED || NOT AVAILABLE)
  13. private String status;
  14. //Book due date
  15. private int[] dueDate = new int[3];
  16. //Constructor without book title
  17. public Book(int id)
  18. {
  19. this.id = id;
  20. this.status = "NOT AVAILABLE";
  21. }
  22. //Constructor with book title
  23. public Book(String title, int id)
  24. {
  25. this.title = title;
  26. this.id = id;
  27. this.status = "AVAILABLE";
  28. }
  29. //Getters and setters
  30. public String getTitle()
  31. {
  32. if (title!=null)
  33. {
  34. return title;
  35. } else {
  36. return "UNDEFINED";
  37. }
  38. }
  39. public String getStatus()
  40. {
  41. return status;
  42. }
  43. public int getId()
  44. {
  45. return id;
  46. }
  47. public void setTitle(String title)
  48. {
  49. this.title = title;
  50. }
  51. //Call to rent book, return if renting is successful
  52. public boolean rent(int[] dueDate)
  53. {
  54. //Check if the book is available to be rented
  55. if(status != "AVAILABLE")
  56. {
  57. return false;
  58. }
  59. //Update the due date of the book
  60. this.dueDate = dueDate;
  61. //Update book status
  62. status = "RENTED";
  63. return true;
  64. }
  65. //Call to return the book
  66. public void returned()
  67. {
  68. //Update book status
  69. status = "AVAILABLE";
  70. }
  71. //Calculate the overdue fine
  72. public double overdueFine(int[] currentDay)
  73. {
  74. double fine;
  75. if(currentDay[0] > dueDate[0] || currentDay[1] > (dueDate[1] + 1))
  76. {
  77. return 5;
  78. }
  79. else if(currentDay[1] > dueDate[1])
  80. {
  81. fine = (double)(currentDay[2] + 30 - dueDate[2]) * 0.25;
  82. }
  83. else
  84. {
  85. fine = (double)(currentDay[2] - dueDate[2]) * 0.25;
  86. }
  87. if(fine > 5)
  88. {
  89. return 5;
  90. }
  91. else
  92. {
  93. return fine;
  94. }
  95. }
  96. }