OOP2

StudyPath.java

1
import java.util.List;
2
3
/**
4
 * StudyPath describes a study path that a student wants to follow. it offers algorithms for suggesting paths and for checking the validity of the studypath.
5
 * @author Maarten Vangeneugden - 1438256
6
 */
7
class StudyPath {
8
		private Study m_study; // The study the student wants to follow.
9
		public Study study() {
10
				return m_study;
11
		}
12
		public void setStudy(Study study) {
13
				m_study = study;
14
		}
15
16
		private List<Course> m_courses; // A list containing all courses that can be chosen in this study.
17
		public List<Course> courses() {
18
				return m_courses;
19
		}
20
		public void setCourses(List<Course> courses) {
21
				m_courses = courses;
22
		}
23
24
		/**
25
		 * Checks if the given study path is valid.
26
		 * @return A boolean value. False if the given study is not valid, true if the study path can be done.
27
		 * @pre The list of courses and the study are complete.
28
		 * @post Nothing's changed.
29
		 */
30
		public boolean isValid() { // Checks whether the given study path is valid.
31
				int studyPoints = 0;
32
				for(Course course : courses()) {
33
						studyPoints += course.studyPoints();
34
						if(course.requiredCourses().size() != 0) {
35
								for(Course requiredCourse : course.requiredCourses()) {
36
										if(course.indexOf(requiredCourse) == -1) { // If the required course is not in the study path:
37
												return false;
38
										}
39
										else if(requiredCourse.creditAcquired() == false) {
40
												return false;
41
										}
42
								}
43
						}
44
						}
45
				if(!courses().containsAll(study().mandatoryCourses())) { // If the path does not contain all required courses:
46
						return false;
47
				}
48
				if(studyPoints<60 || studyPoints > 66) {
49
						return false;
50
				}
51
52
				return true;
53
		}
54
}
55
56
}
57