-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse.java~
More file actions
158 lines (98 loc) · 3.6 KB
/
Copy pathCourse.java~
File metadata and controls
158 lines (98 loc) · 3.6 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
import java.io.*;
import java.util.List;
import java.util.ArrayList;
class Course
{
private List <IndividualCourse> list;
private String name, out;
public Course()
{
list = new ArrayList <IndividualCourse>();
}
//ADD COURSE AT THE END OF THE LIST
public void add(IndividualCourse k){
list.add(k);//add course at the end of the list
}
//CREATE NEW COURSE AT THE END OF THE LIST
public void createCourse(IndividualCourse k) throws IOException
{
PrintWriter newCourseFile = new PrintWriter(new FileWriter ("ListOfCourses.dat",true));
newCourseFile.println(k.getCourseName());
newCourseFile.close();
//Creates folder with name of the course
File temp = new File(k.getCourseName()); // Folder path
if(!temp.exists()) {
temp.mkdirs();
}
//Create students file in course folder
File f;
f=new File(k.getCourseName() + "/students.txt");
if(!f.exists()){
f.createNewFile();
} //Add first entry
PrintWriter courseFile = new PrintWriter(new FileWriter (k.getCourseName() + "/students.txt",true));
courseFile.println("null");
courseFile.close();
list.add(k);//add course at the end of the list
}
//REMOVES COURSE OBJECT FROM THE LIST
public void deleteCourse(int index) throws IOException
{
//Delete folder
File dir = new File(list.get(index).getCourseName()); // Folder path
deleteFolder(dir); //Delete folder of the course
list.remove(index); //removes course object form the list
//Put new array to the file
PrintWriter delCourseFile = new PrintWriter(new FileWriter ("ListOfCourses.dat"));
for(int j = 0; j < list.size(); j++)
{
delCourseFile.println(list.get(j).getCourseName());
}
delCourseFile.close();
}
//START OF DELETE COURSE FOLDER
public static boolean deleteFolder(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i=0; i<children.length; i++) {
boolean success = deleteFolder(new File(dir, children[i]));
}
}
return dir.delete();
}
//end of DELETE_FOLDER
//START OF EDIT COURSE
public void editCourse(int nm, String cr) throws IOException
{
// Rename folder name
File file = new File(list.get(nm).getCourseName());
File file2 = new File(cr);
boolean success = file.renameTo(file2);
if (!success) {
}
PrintWriter newCourseFile = new PrintWriter(new FileWriter ("ListOfCourses.dat"));
for(int j = 0; j < list.size(); j++)
{
newCourseFile.println("");
}
newCourseFile.close();
list.get(nm).setCourseName(cr); //Edit element of array
PrintWriter newCoursesFile = new PrintWriter(new FileWriter ("ListOfCourses.dat"));
for(int j = 0; j < list.size(); j++)
{
newCoursesFile.println(list.get(j).getCourseName());
}
newCoursesFile.close();
} //ENDOF EDIT COURSE
//GETS SELECTED OBJECT FROM THE LIST
public IndividualCourse getCourseObject(int no) throws IOException {
list.get(no).createStudentList();
return list.get(no);
}
//SHOWS COURSES LIST
public void show(){
for(int i=1; i<list.size();i++){
Output.println("[" + i + "]" + list.get(i).getCourseName());
}
}
}