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.
 
 

62 lines
986 B

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