From da8ddfb495ff5e4ab2817bf7017b3d72d056ead3 Mon Sep 17 00:00:00 2001 From: BinHong Lee Date: Sun, 3 Apr 2016 19:32:58 -0700 Subject: [PATCH] First draft with of Book.class Added some simple functions including rent() and calculating overdueFine() --- Book.java | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Book.java diff --git a/Book.java b/Book.java new file mode 100644 index 0000000..3102c79 --- /dev/null +++ b/Book.java @@ -0,0 +1,61 @@ +class Book +{ + private int id; + //( AVAILABLE || RENTED || RESERVED || NOT AVAILABLE) + private String status; + private int[] dueDate = new int[3]; + + public Book(int id, String status) + { + this.id = id; + this.status = status; + } + + public String getStatus() + { + return status; + } + + public boolean rent(int[] dueDate) + { + if(status != "AVAILABLE") + { + return false; + } + + this.dueDate = dueDate; + status = "RENTED"; + return true; + } + + public void returned() + { + status = "AVAILABLE"; + } + + public double overdueFine(int[] currentDay) + { + double fine; + if(currentDay[0] > dueDate[0] || currentDay[1] > (dueDate[1] + 1)) + { + return 5; + } + else if(currentDay[1] > dueDate[1]) + { + fine = (double)(currentDay[2] + 30 - dueDate[2]) * 0.25; + } + else + { + fine = (double)(currentDay[2] - dueDate[2]) * 0.25; + } + + if(fine > 5) + { + return 5; + } + else + { + return fine; + } + } +}