-
Notifications
You must be signed in to change notification settings - Fork 0
/
MajorNode.java
87 lines (79 loc) · 2.65 KB
/
MajorNode.java
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
import java.io.*;
import java.util.*;
import java.lang.*;
public class MajorNode {
private String name;
private ArrayList<ClassNode> requiredClasses;
private ArrayList<String> classNames;
public MajorNode(String majorName) throws FileNotFoundException{
Scanner data = new Scanner(new File("majors.txt"));
name = "";
while(data.hasNext() && !name.equals(majorName)){
name = data.nextLine();
}
classNames = new ArrayList<String>();
String[] strClasses = data.nextLine().split(", ");
requiredClasses = new ArrayList<ClassNode>();
for(int i = 0; i < strClasses.length; i++){
requiredClasses.add(new ClassNode(strClasses[i]));
classNames.add(strClasses[i]);
for(String req : requiredClasses.get(i).getPrereqs())
classNames.add(req);
}
}
//print
public String toString(){
String result = name + ": \n";
for(int i = 0; i < requiredClasses.size(); i++){
result += requiredClasses.get(i) + "\n";
}
return result;
}
//classes taken
public void remove(String taken){
for(int i = 0; i < requiredClasses.size(); i++){
if(requiredClasses.get(i).getName().contains(taken)){
requiredClasses.remove(i);
} else {
requiredClasses.get(i).remove(taken);
}
}
}
public int getDepth(String req) {
int depth;
int depth_max = 0;
for (int i = 0; i < requiredClasses.size(); i++) {
if (requiredClasses.get(i).getName().contains(req)) return 0;
depth = requiredClasses.get(i).getDepth(req);
if (depth > depth_max) depth_max = depth;
}
return depth_max;
}
public void makeSchedule() {
int i = 1;
ArrayList<Integer> depths = new ArrayList<Integer>();
for (int j = 0; j < classNames.size(); j++)
depths.add(getDepth(classNames.get(i)));
while (requiredClasses.size() > 0) {
System.out.println(depths.toString());
System.out.println("Quarter " + i + ":");
List<String> classes = new ArrayList<String>();
for (int k = 0; k < 3; k++) {
int depth_max = 0;
int max_index = 0;
for (int j = 0; j < classNames.size(); j++) {
if (depths.get(j) > depth_max) {
depth_max = depths.get(j);
max_index = j;
}
}
classes.add(classNames.get(max_index));
System.out.println(classNames.get(max_index));
classNames.remove(max_index);
depths.remove(max_index);
}
for (String taken : classes) remove(taken);
i++;
}
}
}