-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchool.java
More file actions
83 lines (63 loc) · 1.72 KB
/
School.java
File metadata and controls
83 lines (63 loc) · 1.72 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
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;
import javax.swing.JOptionPane;
public abstract class School implements Enrollment_Method {
private String lastName = "";
private String firstName = "";
private String middleName = "";
private int age = 0;
private String course = "";
private String id = "";
School(){
}
School(String lastName, String firstName, String middleName, int age, String course){
this.lastName = lastName;
this.firstName = firstName;
this.middleName = middleName;
this.age = age;
this.course = course;
}
School(String name){
deleteStudent(name);
}
public String getID() {
Random rand = new Random();
int i = 0;
String reference = "";
while(i < 10) {
reference+= rand.nextInt(9);
i++;
}
return reference;
}
String path= "D:Student\\";
File folder = new File(path);
public void addStudent() {
try {
folder.mkdir();
File file = new File(path+lastName+".txt");
file.createNewFile();
FileWriter write = new FileWriter(path+lastName+".txt");
write.write(getID()+","+lastName+","+firstName+","+middleName+","+age+","+course);
write.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void deleteStudent(String name) {
File del = new File(path+name+".txt");
if(del.exists()) {
del.delete();
JOptionPane.showMessageDialog(null, "Student Deleted");
}
else
JOptionPane.showMessageDialog(null, "No Student Record");
}
public void showStudent() {
File retrieve =new File(path);
String[] re = retrieve.list();
JOptionPane.showMessageDialog(null, re);
}
}