This repository was archived by the owner on May 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFine.java
More file actions
82 lines (67 loc) · 2.11 KB
/
Fine.java
File metadata and controls
82 lines (67 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
*
* @author Rhys Jacka, 955475
* @author Dale Butt, 957450
*
* This class represents a Fine.
*
*/
import java.time.LocalDate;
public class Fine {
private String itemName = "";
private double fineAmount;
public int daysOverDue;
private double fineRemainder = 0.0;
public Fine(OnLoan contract) {
if (contract.getResourceCopy().getBook() != null) {
this.itemName = contract.getResourceCopy().getBook().getTitle();
} else if (contract.getResourceCopy().getDVD() != null) {
this.itemName = contract.getResourceCopy().getDVD().getTitle();
} else if (contract.getResourceCopy().getLaptop() != null) {
this.itemName = contract.getResourceCopy().getLaptop().getTitle();
}
this.calculateDaysOver(contract.getStartDate(), contract.getStartDate());
this.calculateTotalFine(contract.getResourceCopy());
}
public double getFinePrice() {
return fineAmount;
}
public void calculateTotalFine(Copy borrowedCopy){
double totalCost = 0.0;
// if it a book or dvd, fine them 2 pound per day(max of 25 pound)
if (borrowedCopy.getBook() != null || borrowedCopy.getDVD() != null) {
double lateCost;
if (this.daysOverDue > 10) {
lateCost = 100.00;
} else {
lateCost = 2.00 * this.daysOverDue;
}
totalCost = totalCost + lateCost;
// if it a laptop, fine them 10 pound per day(max of 100 pound)
} else if(borrowedCopy.getLaptop() != null) {
double lateCost;
if (this.daysOverDue > 10) {
lateCost = 100.00;
} else {
lateCost = 10.00 * this.daysOverDue;
}
totalCost = totalCost + lateCost;
}
this.fineAmount = totalCost;
this.fineRemainder = this.fineAmount;
}
/**
* Calculates how many days over due
* @param daysOverDue - how many days a resource is overdue
* @return daysOverDue
*/
public int calculateDaysOver(LocalDate currentDate, LocalDate dueDate){
System.out.println(dueDate + " : " + currentDate);
if (currentDate.getMonth() == dueDate.getMonth()) {
this.daysOverDue = dueDate.compareTo(currentDate);
} else if (dueDate.compareTo(currentDate) == 1) {
this.daysOverDue = 28;
}
return daysOverDue;
}
}