OOP2

Added new files, worked on existing files.

Author
Vngngdn
Date
Aug. 16, 2016, 9:55 a.m.
Hash
41d81bf83b3b3087ee35ebc32c0d96292feb8ab1
Parent
2ab812b4443d46e4fbcff6d2b90b7b531b058589
Modified files
Challenge 4/Article.java
Challenge 4/Client.java
Challenge 4/Controller.java
Challenge 4/Main.java
Challenge 4/Penalty.java
Challenge 4/Queue.java

Challenge 4/Article.java

6 additions and 4 deletions.

View changes Hide changes
1
1
 * @author Maarten Vangeneugden - 1438256
2
2
 */
3
3
public class Article {
4
4
5
5
	private int ID;
6
6
	private String title;
7
7
	private String series;
8
8
	private ArticleType type;
9
9
	private Category category;
10
-
+
10
	private String lendedSince;
+
11
11
12
	public Article(int ID, String title, String series, ArticleType type, Category category) { 
12
-
		this.ID = ID;
+
13
		this.ID = ID;
13
14
		this.title = title;
14
15
		this.series = series;
15
16
		this.type = type;
16
17
		this.category = category;
17
18
	}
+
19
	}
18
20
19
21
	public void setID(int ID) {
20
22
		this.ID = ID;
21
23
	}
22
24
23
25
	public int getID() {	
24
26
		return ID;
25
27
	}
26
28
27
29
	public void setTitle(String title) {
28
30
		this.title = title;
29
31
	}
30
32
31
33
	public String getTitle() {	
32
34
		return title;
33
35
	}
34
36
35
37
	public void setSeries(String series) {
36
38
		this.series = series;
37
39
	}
38
40
39
41
	public Series getSeries() {	
40
42
		return series;
41
43
	}
42
44
43
45
	public void setType(ArticleType type) {
44
46
		this.type = type;
45
47
	}
46
48
47
49
	public ArticleType getType() {	
48
50
		return type;
49
51
	}
50
52
51
53
	public void setCategory(Category category) {
52
-
		this.category = category;
+
54
		this.category = category;
53
55
	}
54
56
55
57
	public Category getCategory() {	
56
-
		return category;
+
58
		return category;
57
59
	}
58
60
59
61
}
60
62

Challenge 4/Client.java

68 additions and 0 deletions.

View changes Hide changes
1
1
2
2
/**
3
3
 * @author Maarten Vangeneugden - 1438256
4
4
 */
5
5
public class Client {
6
6
7
7
	private int ID;
+
8
	private String name;
+
9
	private String email;
+
10
	private List<String> preferences;
+
11
	private String birthDate;
+
12
	private String memberSince;
+
13
+
14
	public Client(int ID, String name, String email, List<String> preferences, String birthDate, String memberSince) { 
+
15
		this.ID = ID;
+
16
		this.name = name;
+
17
		this.email = email;
+
18
		this.preferences = preferences;
+
19
		this.birthDate = birthDate;
+
20
		this.memberSince = memberSince;
+
21
	}
+
22
+
23
	public void setID(int ID) {
+
24
		this.ID = ID;
+
25
	}
+
26
+
27
	public int getID() {	
+
28
		return ID;
+
29
	}
+
30
+
31
	public void setName(String name) {
+
32
		this.name = name;
+
33
	}
+
34
+
35
	public String getName() {	
+
36
		return name;
+
37
	}
+
38
+
39
	public void setEmail(String email) {
+
40
		this.email = email;
+
41
	}
+
42
+
43
	public String getEmail() {	
+
44
		return email;
+
45
	}
+
46
+
47
	public void setPreferences(List<String> preferences) {
+
48
		this.preferences = preferences;
+
49
	}
+
50
+
51
	public List<String> getPreferences() {	
+
52
		return preferences;
+
53
	}
+
54
+
55
	public void setBirthDate(String birthDate) {
+
56
		this.birthDate = birthDate;
+
57
	}
+
58
+
59
	public String getBirthDate() {	
+
60
		return birthDate;
+
61
	}
+
62
+
63
	public void setMemberSince(String memberSince) {
+
64
		this.memberSince = memberSince;
+
65
	}
+
66
+
67
	public String getMemberSince() {	
+
68
		return memberSince;
+
69
	}
+
70
+
71
}
+
72
public class Client {
+
73
+
74
	private int ID;
8
75
	private String name;
9
76
	private String email;
10
77
	private List<String> preferences;
11
78
12
79
	public Client(int ID, String name, String email, List<String> preferences) { 
13
80
		this.ID = ID;
14
81
		this.name = name;
15
82
		this.email = email;
+
83
		this.email = email;
16
84
		this.preferences = preferences;
17
85
	}
18
86
19
87
	public void setID(int ID) {
20
88
		this.ID = ID;
21
89
	}
22
90
23
91
	public int getID() {	
24
92
		return ID;
25
93
	}
26
94
27
95
	public void setName(String name) {
28
96
		this.name = name;
29
97
	}
30
98
31
99
	public String getName() {	
32
100
		return name;
33
101
	}
34
102
35
103
	public void setEmail(String email) {
36
104
		this.email = email;
37
105
	}
38
106
39
107
	public String getEmail() {	
40
108
		return email;
41
109
	}
42
110
43
111
	public void setPreferences(List<String> preferences) {
44
112
		this.preferences = preferences;
45
113
	}
46
114
47
115
	public List<String> getPreferences() {	
48
116
		return preferences;
49
117
	}
50
118
51
119
}
52
120

Challenge 4/Controller.java

97 additions and 0 deletions.

View changes Hide changes
+
1
+
2
	private List<Article> articles;
+
3
	private List<Client> clients;
+
4
	private List<Penalty> penalties;
+
5
+
6
	public Controller(List<Article> articles, List<Client> clients) { 
+
7
		this.articles = articles;
+
8
		this.clients = clients;
+
9
		
+
10
	}
+
11
+
12
	/**
+
13
	 * Creates the main screen, out of which the user can choose the different
+
14
	 * things to do.
+
15
	 */
+
16
	private void createMainScreen() {
+
17
		Window gui = new Window("Bibliotheek");
+
18
		gui.createButton(
+
19
				"Leen artikels uit",
+
20
				"",
+
21
				"createLendingScreen",
+
22
				this
+
23
				);
+
24
		gui.createButton(
+
25
				"Beheer wachtlijsten",
+
26
				"",
+
27
				"createQueueScreen",
+
28
				this
+
29
				);
+
30
		gui.createButton(
+
31
				"Schrijf boete uit",
+
32
				"",
+
33
				"createPenaltyScreen",
+
34
				this
+
35
				);
+
36
	}
+
37
+
38
	private void createLendingScreen() {
+
39
		lendingScreen = new Window("Artikels uitlenen");
+
40
		lendingScreen.addComboBox(this.getClients().toArray());
+
41
+
42
	}
+
43
+
44
	private void createPenaltyScreen() {
+
45
		penaltyScreen = new Window("Boetes beheren");
+
46
		String[] penaltyTitles = new String[this.penalties.length()];
+
47
		for(int i=0; i<this.penalties.length(); i++) {
+
48
			Penalty penalty = this.penalties.get(i);
+
49
			String clientName = penalty.getClient().getName();
+
50
			String articleName = penalty.getArticles.get(0).getName();
+
51
			String penaltyTitle = articleName +" door "+ clientName;
+
52
			penaltyTitles[i] = penaltyTitle;
+
53
		}
+
54
+
55
		JCheckBox[] paidPenalties = new JCheckBox[this.penalties.length()];
+
56
		for(int i=0; i<this.penalties.length(); i++) {
+
57
			paidPenalties[i] = penaltyScreen.createCheckbox(penaltyTitles[i]);
+
58
		}
+
59
+
60
+
61
+
62
+
63
+
64
+
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
	public void setClients(List<Client> clients) {
+
76
		this.clients = clients;
+
77
	}
+
78
+
79
	public List<Client> getClients() {	
+
80
		return clients;
+
81
	}
+
82
+
83
	/**
+
84
	 * Translates a given date to an array of 3 integers.
+
85
	 * @param stringDate The date to translate.
+
86
	 * @pre stringDate must be of form DD-MM-YYYY
+
87
	 */
+
88
	public static int[] getDate(String stringDate) {
+
89
		int[] date = new int[3];
+
90
		String[] dateParts = stringDate.split("-");
+
91
		for(int i=0; i<date.length; i++) {
+
92
			date[i] = Integer.parseInt(dateParts[i]);
+
93
		}
+
94
		return date;
+
95
	}
+
96
}
+
97

Challenge 4/Main.java

31 additions and 1 deletion.

View changes Hide changes
1
1
 * @author Maarten Vangeneugden - 1438256
2
2
 */
3
3
public class Main {
4
4
	public static void main(String[] args) {
5
5
		Window gui = new Window("Bibliotheek");
6
-
	}
+
6
		articles.append(new Article(
+
7
					0,
+
8
					"Erik en het boek",
+
9
					null,
+
10
					ArticleType.BOOK,
+
11
					"roman"
+
12
					));
+
13
		articles.append(new Article(
+
14
					1,
+
15
					"Oorlog en terpentijn",
+
16
					null,
+
17
					ArticleType.BOOK,
+
18
					"roman"
+
19
					));
+
20
		//articles.append(new Article(
+
21
+
22
		List<Client> clients = new ArrayList();
+
23
		List<String> preferences = new ArrayList();
+
24
		preferences.append("misdaad");
+
25
		preferences.append("roman");
+
26
		preferences.append("pop");
+
27
		clients.append(new Client(
+
28
					0,
+
29
					"Jan Janssen",
+
30
					"janjanssen@test.be",
+
31
					
+
32
					"02-05-1965",
+
33
					"01-01-2014",
+
34
+
35
+
36
	}
7
37
}
8
38

Challenge 4/Penalty.java

52 additions and 0 deletions.

View changes Hide changes
+
1
+
2
/**
+
3
 * Represents a penalty that has to be paid.
+
4
 * @author Maarten Vangeneugden
+
5
 */
+
6
public class Penalty {
+
7
+
8
	private Client client;
+
9
	private List<Article> articles;
+
10
+
11
	public Penalty(Client client, List<Article> articles) {
+
12
		this.client = client;
+
13
		this.article = articles;
+
14
	}
+
15
+
16
	/**
+
17
	 * By calling this method, the caller gets the total penalty back.
+
18
	 * The current way of doing this is as follows:
+
19
	 * - Per day: €0,30
+
20
	 * - €0.15 if client is a minor
+
21
	 * - If the Penalty concerns a multiple of articles
+
22
	 */
+
23
	public float computePenalty() {
+
24
		float totalPenalty = 0;
+
25
		List<String> detectedSeries = new ArrayList();
+
26
		for(Article article: this.getArticles()) {
+
27
			if(article.getSeries() != null) {
+
28
				if(!detectedSeries.contains(article.getSeries())) {
+
29
					detectedSeries.add(article.getSeries());
+
30
					
+
31
		
+
32
+
33
		return totalPenalty;
+
34
	}
+
35
	public void setClient(Client client) {
+
36
		this.client = client;
+
37
	}
+
38
+
39
	public Client getClient() {	
+
40
		return client;
+
41
	}
+
42
+
43
	public void setArticles(List<Article> articles) {
+
44
		this.articles = articles;
+
45
	}
+
46
+
47
	public List<Article> getArticles() {	
+
48
		return articles;
+
49
	}
+
50
+
51
}
+
52

Challenge 4/Queue.java

37 additions and 0 deletions.

View changes Hide changes
+
1
+
2
	private Article article;
+
3
	private int waitTime;
+
4
	private ArrayList<Client> clientsWaiting;
+
5
+
6
	public Queue(Article article, int waitTime, ArrayList<Client> clientsWaiting) { 
+
7
		this.article = article;
+
8
		this.waitTime = waitTime;
+
9
		this.clientsWaiting = clientsWaiting;
+
10
	}
+
11
+
12
	public void setArticle(Article article) {
+
13
		this.article = article;
+
14
	}
+
15
+
16
	public Article getArticle() {	
+
17
		return article;
+
18
	}
+
19
+
20
	public void setWaitTime(int waitTime) {
+
21
		this.waitTime = waitTime;
+
22
	}
+
23
+
24
	public int getWaitTime() {	
+
25
		return waitTime;
+
26
	}
+
27
+
28
	public void setClientsWaiting(ArrayList<Client> clientsWaiting) {
+
29
		this.clientsWaiting = clientsWaiting;
+
30
	}
+
31
+
32
	public ArrayList<Client> getClientsWaiting() {	
+
33
		return clientsWaiting;
+
34
	}
+
35
+
36
}
+
37