OOP2

Applied small changes to the first challenge.

Author
Vngngdn
Date
Nov. 2, 2016, 5:43 p.m.
Hash
8cae9e7880bf439dbdf2cb88af4943882d72e4b4
Parent
b3673cbdc53cb5e72195a10ccdfaefe7f04d71b8
Modified files
Challenge 1/Course.java
Challenge 4/Controller.java

Challenge 1/Course.java

63 additions and 0 deletions.

View changes Hide changes
+
1
import java.util.List;
1
2
2
3
/**
3
4
 * Course: Represents a course that is a part of a study.
4
5
 * @author Maarten Vangeneugden - 1438256
5
6
 */
6
7
class Course {
+
8
+
9
	private String name;
+
10
	private int studyPoints;
+
11
	private int semester;
+
12
	private int ID;
+
13
	private boolean pass;
+
14
	private List<Course> requiredCourses;
+
15
+
16
	public Course(String name, int studyPoints, int semester, int ID, boolean pass, List<StudyCourse> requiredCourses) {
+
17
		this.name = name;
+
18
		this.studyPoints = studyPoints;
+
19
		this.semester = semester;
+
20
		this.ID = ID;
+
21
		this.pass = pass;
+
22
		this.requiredCourses = requiredCourses;
+
23
	}
+
24
+
25
	public void setName(String name) {
+
26
		this.name = name;
+
27
	}
+
28
	public String getName() {
+
29
		return name;
+
30
	}
+
31
+
32
	public void setStudyPoints(int studyPoints) {
+
33
		this.studyPoints = studyPoints;
+
34
	}
+
35
	public int getStudyPoints() {
+
36
		return studyPoints;
+
37
	}
+
38
+
39
	public void setSemester(int semester) {
+
40
		this.semester = semester;
+
41
	}
+
42
	public int getSemester() {
+
43
		return semester;
+
44
	}
+
45
+
46
	public void setID(int ID) {
+
47
		this.ID = ID;
+
48
	}
+
49
	public int getID() {
+
50
		return ID;
+
51
	}
+
52
+
53
	public void setPass(boolean pass) {
+
54
		this.pass = pass;
+
55
	}
+
56
	public boolean getPass() {
+
57
		return pass;
+
58
	}
+
59
+
60
	public List<Course> getRequiredCourses() {
+
61
			return this.requiredCourses;
+
62
	}
+
63
	public void setRequiredCourses(List<Course> requiredCourses) {
+
64
			this.requiredCourses = requiredCourses;
+
65
	}
+
66
+
67
}
+
68
+
69
class Course {
7
70
		private String m_name; // The name of the course.
8
71
		public String name() {
9
72
				return m_name;
10
73
		}
11
74
		public void setName(String name) {
12
75
				m_name = name;
13
76
		}
14
77
15
78
		private int m_studyPoints; // An integer value representing how much study points this course has.
16
79
		public int studyPoints() {
17
80
				return m_studyPoints;
18
81
		}
19
82
		public void setStudyPoints(int studyPoints) {
20
83
				m_studyPoints = studyPoints;
21
84
		}
22
85
23
86
		private int m_semester; // Integer that represents in which semester this course takes place.
24
87
		public int semester() {
25
88
				return m_semester;
26
89
		}
27
90
		public void setSemester(int semester) {
28
91
				m_semester = semester;
29
92
		}
30
93
		
31
94
		private int m_ID; // Integer value representing the unique ID of this course.
32
95
		public int ID() {
33
96
				return m_ID;
34
97
		}
35
98
		public void setID(int ID) {
36
99
				m_ID = ID;
37
100
		}
38
101
39
102
		private List<Course> m_requiredCourses; // A list of courses that are required to follow this course.
40
103
		public List<Course> requiredCourses() {
41
104
				return m_requiredCourses;
42
105
		}
43
106
		public void setRequiredCourses(List<Course> requiredCourses) {
44
107
				m_requiredCourses = requiredCourses;
45
108
		}
46
109
47
110
		private boolean m_passed; // A boolean value that holds whether this course has been passed, indicating a credit for it has been acquired by the student.
48
111
		public boolean creditAcquired() {
49
112
				return m_passed;
50
113
		}
51
114
		public void setPassed(boolean pass) {
52
115
				m_passed = pass;
53
116
		}
54
117
		
55
118
		public Course(String name, int studyPoints, int semester, int ID, boolean pass) {
56
119
				setName(name);
57
120
				setStudyPoints(studyPoints);
58
121
				setSemester(semester);
59
122
				setID(ID);
60
123
				setPassed(pass);
61
124
		}
62
125
}
63
126

Challenge 4/Controller.java

4 additions and 1 deletion.

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