OOP2

StudyPath.java

1
import java.util.List;
2
import java.util.Observable;
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 extends Observable {
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
		public int studyPoints() {
17
			int studyPoints = 0;
18
			for(Course course : courses()) {
19
				studyPoints += course.studyPoints();
20
			}
21
			return studyPoints;
22
		}
23
24
		private List<Course> m_courses; // A list containing all courses that can be chosen in this study.
25
		public List<Course> courses() {
26
				return m_courses;
27
		}
28
		public void setCourses(List<Course> courses) {
29
				m_courses = courses;
30
		}
31
32
		/**
33
		 * Checks if the given study path is valid.
34
		 * @return A boolean value. False if the given study is not valid, true if the study path can be done.
35
		 * @pre The list of courses and the study are complete.
36
		 * @post Nothing's changed.
37
		 */
38
		public boolean isValid() { // Checks whether the given study path is valid.
39
				int studyPoints = 0;
40
				for(Course course : courses()) {
41
						studyPoints += course.studyPoints();
42
						if(course.requiredCourses().size() != 0) {
43
								for(Course requiredCourse : course.requiredCourses()) {
44
										if(course.requiredCourses().indexOf(requiredCourse) == -1) { // If the required course is not in the study path:
45
												return false;
46
										}
47
										else if(requiredCourse.creditAcquired() == false) {
48
												return false;
49
										}
50
								}
51
						}
52
						}
53
				if(!courses().containsAll(study().mandatoryCourses())) { // If the path does not contain all required courses:
54
						return false;
55
				}
56
				if(studyPoints<60 || studyPoints > 66) {
57
						return false;
58
				}
59
60
				return true;
61
		}
62
63
		/**
64
		 * Returns a list of courses that can be followed.
65
		 * @return see description
66
		 */
67
		public List<Course> suggestedCourses() {
68
		}
69
}
70