This repository was archived by the owner on Feb 16, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDepartment.java
More file actions
Latest commit
143 lines (110 loc) · 3.43 KB
/
Copy pathDepartment.java
File metadata and controls
143 lines (110 loc) · 3.43 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
/*import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileOutputStream;*/
importjava.io.Serializable;
importjava.util.Collections;
importjava.util.Comparator;
importjava.util.LinkedList;
publicclassDepartmentimplementsSerializable {
privatestaticfinallongserialVersionUID = 1L;
privateStringcode;
privateStringname;
privateLinkedList<Student> students = newLinkedList<Student>();
publicDepartment(Stringcode, Stringname) {
this.code = code;
this.name = name;
/* try {
ObjectInputStream objReader = new ObjectInputStream(new FileInputStream("departments.dat"));
} catch (FileNotFoundException createFile) {
System.out.println("File was not found, creating file with default values");
try {
ObjectOutputStream objCreator = new ObjectOutputStream(new FileOutputStream("departments.dat"));
objCreator.writeObject(students);
objCreator.close();
} catch (IOException e) {
}
} catch (IOException e) {
System.out.println(e.getMessage());
} */
}
staticfinalComparator<Student> ID_ORDER = newComparator<Student>() {
@Override
publicintcompare(Studentstu1, Studentstu2) {
intID1 = stu1.getId();
intID2 = stu2.getId();
if (ID1 == ID2)
return0;
elseif (ID1 > ID2)
return1;
else
return -1;
}
};
staticfinalComparator<Student> GPA_ORDER = newComparator<Student>() {
publicintcompare(Studentstu1, Studentstu2) {
if (stu1.getGPA() > stu2.getGPA())
return1;
elseif (stu1.getGPA() < stu2.getGPA())
return -1;
else
return0;
}
};
staticfinalComparator<Student> NAME_ORDER = newComparator<Student>() {
@Override
publicintcompare(Studentstu1, Studentstu2) {
Stringname1 = stu1.getName();
Stringname2 = stu2.getName();
returnname1.compareTo(name2);
}
};
publicvoidsortStudents(intorder) {
if (order == 0)
Collections.sort(students, ID_ORDER);
elseif (order == 1)
Collections.sort(students, GPA_ORDER);
elseif (order == 2)
Collections.sort(students, NAME_ORDER);
}
publicLinkedList<Student> getStudents() {
returnstudents;
}
publicvoidsetStudents(LinkedList<Student> students) {
this.students = students;
}
publicStringtoString() {
Stringdetails = code + " " + name;
returndetails;
}
publicvoidaddStudent(Studentstudent) {
students.add(student);
}
/*
* public static void main(String[] args) { LinkedList<Department> dpt; try {
* ObjectInputStream objReader = new ObjectInputStream(new
* FileInputStream("departments.dat"));
*
* LinkedList<Department> readObject = extracted(objReader);
* LinkedList<Department> temp = readObject;
*
* System.out.println(temp); objReader.close();
*
* } catch (FileNotFoundException createFile) {
*
* System.out.println("File was not found, creating file with default values");
*
* } catch (IOException e) { } catch (ClassNotFoundException e) { // TODO
* Auto-generated catch block e.printStackTrace(); }
*
*
*
* }
*
* private static LinkedList<Department> extracted(ObjectInputStream objReader)
* throws IOException, ClassNotFoundException { return (LinkedList<Department>)
* objReader.readObject(); }
*/
}