OOP2

Apparantly, I forgot to add the fourth try to the tracker back then. Doing that now.

Author
Vngngdn
Date
Oct. 20, 2016, 5:20 p.m.
Hash
baa12ac6f760288ff5a02ddd7ae556840a1447c4
Parent
41d81bf83b3b3087ee35ebc32c0d96292feb8ab1
Modified files
Challenge 4/Article.java
Challenge 4/ArticleType.java
Challenge 4/Client.java
Challenge 4/Controller.java
Challenge 4/LendingController.java
Challenge 4/Main.java
Challenge 4/Penalty.java
Challenge 4/PenaltyController.java
Challenge 4/Queue.java
Challenge 4/ontwerpkeuzes.txt

Challenge 4/Article.java

8 additions and 1 deletion.

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 String category;
10
10
	private String lendedSince;
11
11
12
12
	public Article(int ID, String title, String series, ArticleType type, String category, String lendedSince) { 
13
13
		this.ID = ID;
14
14
		this.title = title;
15
15
		this.series = series;
16
16
		this.type = type;
17
17
		this.category = category;
18
18
		this.lendedSince = lendedSince;
19
19
	}
20
20
21
21
	public void setID(int ID) {
22
22
		this.ID = ID;
23
23
	}
24
24
25
25
	public int getID() {	
26
26
		return ID;
27
27
	}
28
28
29
29
	public void setTitle(String title) {
30
30
		this.title = title;
31
31
	}
32
32
33
33
	public String getTitle() {	
34
34
		return title;
35
35
	}
36
36
37
37
	public void setSeries(String series) {
38
38
		this.series = series;
39
39
	}
40
40
41
41
	public Series getSeries() {	
42
-
		return series;
+
42
		return series;
43
43
	}
44
44
45
45
	public void setType(ArticleType type) {
46
46
		this.type = type;
47
47
	}
48
48
49
49
	public ArticleType getType() {	
50
50
		return type;
51
51
	}
52
52
53
53
	public void setCategory(String category) {
54
54
		this.category = category;
55
55
	}
56
56
57
57
	public String getCategory() {	
58
58
		return category;
59
59
	}
60
60
61
61
}
+
62
		this.lendedSince = lendedSince;
+
63
	}
+
64
+
65
	public String getLendedSince() {	
+
66
		return lendedSince;
+
67
	}
+
68
}
62
69

Challenge 4/ArticleType.java

3 additions and 0 deletions.

View changes Hide changes
+
1
 * @author Maarten Vangeneugden - 1438256
+
2
 */
+
3
public enum ArticleType {
1
4
	BOOK,
2
5
	CD,
3
6
	DVD
4
7
}
5
8

Challenge 4/Client.java

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

Challenge 4/Controller.java

51 additions and 22 deletions.

View changes Hide changes
+
1
import java.util.ArrayList;
+
2
import javax.swing.JCheckBox;
+
3
import javax.swing.JComponent;
+
4
import javax.swing.JButton;
+
5
/**
+
6
 * @author Maarten Vangeneugden - 1438256
+
7
 */
+
8
public class Controller {
1
9
2
10
	private List<Article> articles;
3
11
	private List<Client> clients;
4
12
	private List<Penalty> penalties;
5
13
+
14
	private List<JComponent> mainScreenComponents;
+
15
6
16
	public Controller(List<Article> articles, List<Client> clients) { 
7
17
		this.articles = articles;
8
18
		this.clients = clients;
9
19
		
+
20
		this.mainScreenComponents = new ArrayList();
+
21
		this.createMainScreen();
+
22
		
10
23
	}
11
24
12
25
	/**
13
26
	 * Creates the main screen, out of which the user can choose the different
14
27
	 * things to do.
15
28
	 */
16
29
	private void createMainScreen() {
17
30
		Window gui = new Window("Bibliotheek");
18
31
		gui.createButton(
19
-
				"Leen artikels uit",
+
32
				"Leen artikels uit",
20
33
				"",
21
34
				"createLendingScreen",
22
35
				this
23
36
				);
24
-
		gui.createButton(
25
-
				"Beheer wachtlijsten",
+
37
		this.mainScreenComponents.add(gui.createButton(
+
38
				"Beheer wachtlijsten",
26
39
				"",
27
40
				"createQueueScreen",
28
41
				this
29
42
				);
30
-
		gui.createButton(
31
-
				"Schrijf boete uit",
+
43
		this.mainScreenComponents.add(gui.createButton(
+
44
				"Schrijf boete uit",
32
45
				"",
33
46
				"createPenaltyScreen",
34
47
				this
35
48
				);
36
-
	}
+
49
	}
37
50
38
51
	private void createLendingScreen() {
39
-
		lendingScreen = new Window("Artikels uitlenen");
40
-
		lendingScreen.addComboBox(this.getClients().toArray());
41
-
42
-
	}
+
52
	}
43
53
44
54
	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
-
		}
+
55
	 * Swaps the visibility state of the main screen buttons.
+
56
	 */
+
57
	private void swapMainButtonsState() {
+
58
		for(JComponent component: this.mainScreenComponents) {
+
59
			component.setVisible(!component.isVisible());
+
60
		}
54
61
+
62
55
63
		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
-
		}
+
64
		//this.swapMainButtonsState();
+
65
		LendingController lendingController = new LendingController(this.articles, this.clients, this.window);
+
66
		//this.swapMainButtonsState();
+
67
+
68
		Window lendingScreen = new Window("Artikels uitlenen");
+
69
		lendingScreen.addComboBox(this.getClients().toArray(new String[0]));
+
70
		List<Article> availableArticles = new ArrayList();
+
71
		for(Article article: this.articles) {
+
72
			if(article.getLendedSince() == null) { // Available article
+
73
				availableArticles.add(article);
+
74
			}
+
75
		}
59
76
60
77
61
78
+
79
+
80
	public void createPenaltyScreen() {
+
81
		//this.swapMainButtonsState();
+
82
		//this.window.createButton("Sluiten", "", "closeWindow", this);
+
83
		PenaltyController penaltyController = new PenaltyController(this.penalties, this.window);
+
84
		//JButton closeButton = this.window.createButton("Sluiten", "", "removePenalties", penaltyController);
+
85
		//this.swapMainButtonsState();
+
86
	}
+
87
+
88
+
89
+
90
62
91
63
92
64
93
65
94
		
66
95
67
96
	public void setArticles(List<Article> articles) {
68
97
		this.articles = articles;
69
98
	}
70
99
71
100
	public List<Article> getArticles() {	
72
101
		return articles;
73
102
	}
74
103
75
104
	public void setClients(List<Client> clients) {
76
105
		this.clients = clients;
77
106
	}
78
107
79
108
	public List<Client> getClients() {	
80
109
		return clients;
81
110
	}
82
111
83
112
	/**
84
113
	 * Translates a given date to an array of 3 integers.
85
114
	 * @param stringDate The date to translate.
86
115
	 * @pre stringDate must be of form DD-MM-YYYY
87
116
	 */
88
117
	public static int[] getDate(String stringDate) {
89
118
		int[] date = new int[3];
90
119
		String[] dateParts = stringDate.split("-");
91
120
		for(int i=0; i<date.length; i++) {
92
121
			date[i] = Integer.parseInt(dateParts[i]);
93
122
		}
94
123
		return date;
95
124
	}
96
125
}
97
126

Challenge 4/LendingController.java

61 additions and 0 deletions.

View changes Hide changes
+
1
import java.util.ArrayList;
+
2
import javax.swing.JCheckBox;
+
3
import javax.swing.JButton;
+
4
import javax.swing.JComponent;
+
5
/**
+
6
 * @author Maarten Vangeneugden - 1438256
+
7
 */
+
8
public class LendingController {
+
9
+
10
	private List<Article> articles;
+
11
	private List<Client> clients;
+
12
	private Window window;
+
13
	private List<JComponent> components;
+
14
+
15
	public LendingController(List<Article> articles, List<Client> clients, Window window) { 
+
16
		this.articles = articles;
+
17
		this.clients = clients;
+
18
		this.window = window;
+
19
		//this.components.add(this.window.createButton("Sluiten", "", "closeWindow", this));
+
20
		this.createWindow();
+
21
	}
+
22
+
23
	private void createWindow() {
+
24
		String[] clientNames = new String[this.clients.size()];
+
25
		for(int i=0; i<clientNames.length; i++) {
+
26
			clientNames[i] = this.clients.get(i).getName();
+
27
		}
+
28
+
29
		this.components.add(this.window.addComboBox(clientNames));
+
30
	}
+
31
		
+
32
	public void closeWindow() {
+
33
+
34
	}
+
35
+
36
	public void setArticles(List<Article> articles) {
+
37
		this.articles = articles;
+
38
	}
+
39
+
40
	public List<Article> getArticles() {	
+
41
		return articles;
+
42
	}
+
43
+
44
	public void setClients(List<Client> clients) {
+
45
		this.clients = clients;
+
46
	}
+
47
+
48
	public List<Client> getClients() {	
+
49
		return clients;
+
50
	}
+
51
+
52
	public void setWindow(Window window) {
+
53
		this.window = window;
+
54
	}
+
55
+
56
	public Window getWindow() {	
+
57
		return window;
+
58
	}
+
59
+
60
}
+
61

Challenge 4/Main.java

16 additions and 10 deletions.

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

Challenge 4/Penalty.java

26 additions and 3 deletions.

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

Challenge 4/PenaltyController.java

63 additions and 0 deletions.

View changes Hide changes
+
1
import java.util.List;
+
2
import java.util.ArrayList;
+
3
import javax.swing.JCheckBox;
+
4
import javax.swing.JButton;
+
5
+
6
/**
+
7
 * @author Maarten Vangeneugden - 1438256
+
8
 */
+
9
public class PenaltyController {
+
10
+
11
	private List<Penalty> penalties;
+
12
	private JCheckBox[] checkBoxes;
+
13
	public JButton closeButton;
+
14
	private Window window;
+
15
+
16
	public PenaltyController(List<Penalty> penalties, Window window) { 
+
17
		this.penalties = penalties;
+
18
		this.window = window;
+
19
		this.createPenaltyScreen();
+
20
	}
+
21
+
22
	public void setPenalties(List<Penalty> penalties) {
+
23
		this.penalties = penalties;
+
24
	}
+
25
+
26
	public List<Penalty> getPenalties() {	
+
27
		return penalties;
+
28
	}
+
29
+
30
	public void createPenaltyScreen() {
+
31
		String[] penaltyTitles = new String[this.penalties.size()];
+
32
		for(int i=0; i<this.penalties.size(); i++) {
+
33
			Penalty penalty = this.penalties.get(i);
+
34
			String clientName = penalty.getClient().getName();
+
35
			String articleName = penalty.getArticles().get(0).getTitle();
+
36
			String penaltyTitle = articleName +" door "+ clientName +"("+ Float.toString(penalty.computePenalty()) +")";
+
37
			penaltyTitles[i] = penaltyTitle;
+
38
		}
+
39
+
40
		JCheckBox[] paidPenalties = new JCheckBox[this.penalties.size()];
+
41
		for(int i=0; i<this.penalties.size(); i++) {
+
42
			paidPenalties[i] = this.window.createCheckbox(penaltyTitles[i]);
+
43
		}
+
44
	}
+
45
+
46
	public void removePenalties() {
+
47
		for(int i=0; i<this.checkBoxes.length; i++) {
+
48
			if(this.checkBoxes[i].isSelected()) {
+
49
				this.penalties.remove(i);
+
50
			}
+
51
		}
+
52
		
+
53
		this.closeWindow();
+
54
	}
+
55
+
56
	private void closeWindow() {
+
57
		window.removeComponent(this.closeButton);
+
58
		for(JCheckBox checkBox: this.checkBoxes) {
+
59
			window.removeComponent(checkBox);
+
60
		}
+
61
	}
+
62
}
+
63

Challenge 4/Queue.java

5 additions and 0 deletions.

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

Challenge 4/ontwerpkeuzes.txt

19 additions and 0 deletions.

View changes Hide changes
+
1
Structuur:
+
2
Window-class: een wrapper om snel windows te kunnen maken Swing (View)
+
3
+
4
Controller: Coordineert tussen de verschillende controllers, en houdt de data in
+
5
het programma bij
+
6
+
7
Article: Beschrijft een artikel zoals deze is uitgezet in de opgave.
+
8
Houdt ook bij wanneer een 
+
9
+
10
Boete berekenen:
+
11
Er is een method in de Penalty-class, (computePenalty), waar de boete berekend
+
12
kan worden. Een ontwikkelaar kan desgewenst deze method aanpassen, zodat er
+
13
gemakkelijk een nieuwe manier voor het berekenen van boetes kan worden
+
14
ingebouwd.
+
15
+
16
Data: Ik had niet de kans om snel een goede class te maken voor het correct
+
17
afhandelen van data. Dus heb ik gewoon gesteld om een datum als een string voor
+
18
te stellen, en een static method te maken in de Controller
+
19