-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStudent.java
More file actions
142 lines (140 loc) · 4.1 KB
/
Student.java
File metadata and controls
142 lines (140 loc) · 4.1 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
package application;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Scanner;
//CRSTITLE,DUR,FIRST,ID,LAST,PD,TCHF,TCHL
public class Student {
private String fName;
private String lName;
private String id;
ArrayList<Class> schedule1=new ArrayList<Class>();
ArrayList<Class> schedule2=new ArrayList<Class>();
String[] quals;
/**
* Pulls the name and ID number from a line of data
* @param s-The array of strings from splitting a line in the Main's parseData method
*/
public Student(String[] s){
fName=s[2];
lName=s[4];
id=s[3];
}
/**
* Pulls the name, teacher, semester, and period of a class from a line of data
* @param s The array of strings from splitting a line in the Main's parseData method
*/
public void addClass(String[] s){
if(s[1].equals("S1")){
schedule1.add(new Class(s[0], s[1], Integer.parseInt(s[5]), s[6], s[7]));
}
if(s[1].equals("S2")){
schedule2.add(new Class(s[0], s[1], Integer.parseInt(s[5]), s[6], s[7]));
}
}
/**
* Calls the sort method on the arrays of classes (fields)
*/
public void sortClass(){
Collections.sort(schedule1);
Collections.sort(schedule2);
}
/**
* Returns the full name of a student
* @return Full name
*/
public String getFullName(){
return fName+ " "+lName;
}
/**
* Retrieves a list of hours and minutes for the ending times of each class in an ArrayList
* @param sched The name of the schedule file-Normal, 2 Hour Delay, Half Day, Custom. Defaults to Normal
* @return The schedule file contents formatted as an arrayList of String[]s with a length of 2- 1 for hours, 1 for minutes
*/
public static ArrayList<String[]> parseBellSchedule(String sched){
ArrayList<String[]> bellSchedule=new ArrayList<String[]>();
Scanner s=null;
try {
s=new Scanner(new File("DoNotTouch/Normal"));
s = new Scanner(new File("DoNotTouch/"+sched));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
while(s.hasNextLine()){
bellSchedule.add(s.nextLine().split(":"));
}
return bellSchedule;
}
/**
* Returns a predicted teacher based on when each class ends
* @param c The list of current classes for a student
* @param sched The name of the schedule file-Normal, 2 Hour Delay, Half Day, Custom. Defaults to Normal
* @return The predicted teacher
*/
public static Teacher getTheoreticalTeacher(ArrayList<Class> c, String sched){
ArrayList<String[]> bellSchedule=parseBellSchedule(sched);
Date d=new Date();
try{
if(d.getHours()<Integer.parseInt(bellSchedule.get(0)[0])){
return null;
}else if(d.getHours()==Integer.parseInt(bellSchedule.get(0)[0])){
if(d.getMinutes()<=Integer.parseInt(bellSchedule.get(0)[1])){
return null;
}
}
}catch(Exception e){}
for(int i=1;i<bellSchedule.size();i++){
try{
if(d.getHours()<Integer.parseInt(bellSchedule.get(i)[0])){
return(searchClass(c, i).getTeacher());
}else if(d.getHours()==Integer.parseInt(bellSchedule.get(i)[0])){
if(d.getMinutes()<=Integer.parseInt(bellSchedule.get(i)[1])){
return(searchClass(c,i).getTeacher());
}
}
}catch(Exception e){}
}
return null;
}
/**
* Returns a class given the period
* @param classes The list of a student's current classes
* @param pd The period of the class to find
* @return The class that the student has for Period pd
*/
private static Class searchClass(ArrayList<Class> classes, int pd){
for(Class c:classes){
if(c.getPd()==pd){
return c;
}
}
return null;
}
/**
* Get the student's first name
* @return First name
*/
public String getFirstName(){
return fName;
}
/**
* Get the student's ID number
* @return ID number
*/
public String getID(){
return id;
}
/**
* Get the student's schedule given a semester
* @param sem The semester
* @return The list of classes
*/
public ArrayList<Class> getSchedule(int sem){
if(sem==1){
return schedule1;
}
return schedule2;
}
}