-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
171 lines (148 loc) · 5.42 KB
/
Main.java
File metadata and controls
171 lines (148 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import java.io.*;
import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.WindowConstants;
import java.util.Iterator;
import java.util.LinkedList;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
/*
* @author Andrew Keyes
* Keyesandrew@live.com
*/
public class Main {
public static Student person;
public static String[][] goodMods = new String[25][1];
public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
//Load all the possible modules into an array
Module[] moduleHolder = addModules();
//Ask student for their modules
GUI visuals = new GUI();
person = visuals.getStudent();
while(!visuals.doneAdding()){
Thread.sleep(100);
}
System.out.println("Student entered all courses");
//Compare courses to the available modules
//If the student has all the modules available then add it to the linked list and return the name
Comparator comparethis = new Comparator();
LinkedList<Course> studentCoursees = person.getCourses();
int i = 0;
int b = 0;
while(i<5){
Module module = moduleHolder[i];
boolean fail = false;
boolean meetsReqs = true;
boolean containCourse=false;
float studentModGrade;
LinkedList<Course> usedStudCoursees = new LinkedList<Course>();
//Compares regular prerequisite courses against the courses that the student has entered.
Iterator<Course> preCourses = module.getPrereqs();
while(meetsReqs==true&&preCourses.hasNext()){
Course preCourse = preCourses.next();
int k = 0;
//Loops through student courses to check if they meet that prerequisite
while(k<studentCoursees.size()){
if(comparethis.compare(preCourse.getName(),studentCoursees.get(k).getName())){
containCourse=true;
usedStudCoursees.add(studentCoursees.get(k));
}
k++;
}
if(!containCourse){
meetsReqs = false;
}
}
Iterator<ConditionalCourse> preConditionalCourses = module.getConditionalPreReq();
while(meetsReqs==true&&preConditionalCourses.hasNext()){
ConditionalCourse preConCourse = preConditionalCourses.next();
int k = 0;
float credits=0;
//loop through student courses to check if they meet on of the requirements from the conditional course
while(k<studentCoursees.size()){
if(comparethis.compare(preConCourse, studentCoursees.get(k))){
containCourse=true;
credits+=studentCoursees.get(k).getCredits();
usedStudCoursees.add(studentCoursees.get(k));
}
k++;
}
if(!containCourse||credits<preConCourse.getCredits()){
meetsReqs = false;
}
}
boolean gradeReq=true;
float sum =0;
for(int w=0;w<usedStudCoursees.size();w++){
sum+=usedStudCoursees.get(w).getGrade();
if(usedStudCoursees.get(w).getGrade()<module.getminGradeRequirement()){
gradeReq=false;
}
}
if(sum/usedStudCoursees.size()<module.getGradeRequirement()){
gradeReq=false;
}
if(meetsReqs&&gradeReq){
System.out.println("Student average for the module equals "+ sum/usedStudCoursees.size());
System.out.println("Student meets the qualifications for "+ module.getName());
goodMods[b][0] = module.getName();
b++;
}
i++;
}
visuals.buildMajorList(goodMods);
}
public static Module[] addModules(){
//Module holder
BufferedInputStream mods = null;
Module[] moduleHolder = new Module[11];;
try{
//Open a buffered input stream for the mods list
mods = new BufferedInputStream(new FileInputStream("C:\\Users\\Andrew\\1027B\\ModuleHelper\\src\\ModulesCompSci.txt"));
//Create and add all module
for(int j=0;j<5;j++){
//Read the module line one at a time
ReadModLine modslist = new ReadModLine(mods);
String[] moduleString = modslist.readLine();
Module moduleToAdd = new Module(moduleString[0]);
moduleToAdd.setGradeRequirement(Float.parseFloat(moduleString[1]));
moduleToAdd.setminGradeRequirement(Float.parseFloat(moduleString[2]));
int i=3;
while(moduleString[i]!=null){
//Check whether or not it is a credit, if it is then begin adding the course
if(moduleString[i].charAt(0)>='0'&&moduleString[i].charAt(0)<='9'){
float credits = Float.parseFloat(moduleString[i]);
i++;
//If the course is conditional then start a conditionalcourse until another number is ran into
if(!(moduleString[i+1].charAt(0)>='0'&&moduleString[i+1].charAt(0)<='9')){
ConditionalCourse courseToAdd = new ConditionalCourse(new Course(moduleString[i],credits));
i++;
while(moduleString[i]!=null&&(!(moduleString[i].charAt(0)>='0'&&moduleString[i].charAt(0)<='9'))){
courseToAdd.addCourse(new Course(moduleString[i], credits));
i++;
}
moduleToAdd.addConditionalPreReq(courseToAdd);
}
//Else the course is not conditional then enter a regular course
else{
Course courseToAdd = new Course(moduleString[i], credits);
moduleToAdd.setPrereq(courseToAdd);
i++;
}
}
}
moduleHolder[j] = moduleToAdd;
}
System.out.println("All modules have been added");
}catch(Exception e){
e.printStackTrace();
}
return moduleHolder;
}
}