Penalty.java
1 |
|
2 |
import java.util.ArrayList; |
3 |
|
4 |
/** |
5 |
* Represents a penalty that has to be paid. |
6 |
* @author Maarten Vangeneugden |
7 |
*/ |
8 |
public class Penalty { |
9 |
|
10 |
private Client client; |
11 |
private List<Article> articles; |
12 |
private int overdue; |
13 |
|
14 |
public Penalty(Client client, List<Article> articles, int overdue) { |
15 |
this.client = client; |
16 |
this.articles = articles; |
17 |
this.overdue = overdue; |
18 |
} |
19 |
|
20 |
/** |
21 |
* By calling this method, the caller gets the total penalty back. |
22 |
* The current way of doing this is as follows: |
23 |
* - Per day: €0,30 |
24 |
* - €0.15 if client is a minor |
25 |
* - If the Penalty concerns a multiple of articles |
26 |
*/ |
27 |
public float computePenalty() { |
28 |
float totalPenalty = 0; |
29 |
List<String> detectedSeries = new ArrayList(); |
30 |
List<Article> totalArticles = new ArrayList(); |
31 |
for(Article article: this.getArticles()) { |
32 |
if(article.getSeries() != null) { |
33 |
if(!detectedSeries.contains(article.getSeries())) { |
34 |
detectedSeries.add(article.getSeries()); |
35 |
totalArticles.add(article); |
36 |
} |
37 |
} |
38 |
else { |
39 |
totalArticles.add(article); |
40 |
} |
41 |
} |
42 |
// FIXME: I know this is a primitive way of age counting, |
43 |
// but this should be modified so that it can handle dates |
44 |
// correctly. |
45 |
|
46 |
|
47 |
int age = Controller.getDate(this.client.getBirthDate())[2]; |
48 |
for(Article article: totalArticles) { |
49 |
if(age < 18) { // Compute for minors: |
50 |
totalPenalty += 0.15; |
51 |
} |
52 |
else { |
53 |
totalPenalty += 0.3; |
54 |
} |
55 |
} |
56 |
|
57 |
return totalPenalty; |
58 |
} |
59 |
public void setClient(Client client) { |
60 |
this.client = client; |
61 |
} |
62 |
|
63 |
public Client getClient() { |
64 |
return client; |
65 |
} |
66 |
|
67 |
public void setArticles(List<Article> articles) { |
68 |
this.articles = articles; |
69 |
} |
70 |
|
71 |
public List<Article> getArticles() { |
72 |
return articles; |
73 |
} |
74 |
|
75 |
} |
76 |