-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudent.java
164 lines (144 loc) · 4 KB
/
Student.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
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
159
160
161
162
163
164
import java.io.*;
import java.util.*;
class Student extends Users implements Serializable {
String roll;
String name;
String branch;
Users user = new Users();
ArrayList<Subject> registeredSub;
Grade grade;
Parent parent;
ArrayList<Achievement> achievement;
ArrayList<Memo> memos;
ArrayList<Fine> fines;
Student(){
}
static ArrayList<Student> totalStudentsList = new ArrayList<Student>();
public Student(String name,String roll,String branch,String parName){
this.name=name;
this.roll=roll;
this.branch=branch;
totalStudentsList.add(this);
this.registeredSub = new ArrayList<Subject>();
this.achievement = new ArrayList<Achievement>();
this.parent = new Parent(parName,roll);
this.grade = new Grade();
this.memos = new ArrayList<Memo>();
this.fines = new ArrayList<Fine>();
// StudentMain.saveStud();
this.save();
}
public String getRoll(){
return roll;
}
public String getName(){
return name;
}
public String getBranch(){
return branch;
}
public void setRoll(String r){
this.roll=r;
}
public void setName(String n){
this.name=n;
}
public void setBranch(String b){
this.branch=b;
}
public void addSub(Subject su){
this.registeredSub.add(su);
}
public void addAch(Achievement ac){
this.achievement.add(ac);
}
public void addFine(Fine fn){
this.fines.add(fn);
}
public void addMemo(Memo me){
this.memos.add(me);
}
public boolean checkRegSub(String a){
for(Subject st : registeredSub){
if(st.equals(a)){
return true;
}
}
return false;
}
}
class Test{
public static void main(String[] args) {
ArrayList<Student> arrst = new ArrayList<Student>();
Subject s1 = new Subject("math","15mat123");
Subject s2 = new Subject("phy","15phy123");
Subject s3 = new Subject("soc","15soc123");
Student s4 = new Student("Naveen","63","CSE","Nash");
Faculty s5 = new Faculty("Gopal","55");
// arrst.add(s1);
// arrst.add(s2);
// arrst.add(s3);
// arrst.add
// FileOutputStream fos = null;
// ObjectOutputStream oos = null;
// try{
// fos = new FileOutputStream("Students.ser");
// oos = new ObjectOutputStream(fos);
// oos.writeObject(arrst);
// oos.flush();
// oos.close();
// }
// catch (FileNotFoundException fnfex) {
// fnfex.printStackTrace();
// }
// catch (IOException ioex) {
// ioex.printStackTrace();
// }
// StudentMain.saveStud();
/////////////// De serialization
FileInputStream fis = null;
ObjectInputStream ois = null;
ArrayList<Student> listOfStudents = null;
try {
// reading binary data
fis = new FileInputStream("Data/Students.ser");
// converting binary-data to java-object
ois = new ObjectInputStream(fis);
// reading object's value and casting ArrayList<Customer>
listOfStudents = (ArrayList<Student>)ois.readObject();
}
catch (FileNotFoundException fnfex) {
fnfex.printStackTrace();
}
catch (IOException ioex) {
ioex.printStackTrace();
}
catch (ClassNotFoundException ccex) {
ccex.printStackTrace();
}
for(Student stud : listOfStudents){
System.out.println(stud.getName());
}
ArrayList<Faculty> listOfFaculty = null;
try {
// reading binary data
fis = new FileInputStream("Data/Faculty.ser");
// converting binary-data to java-object
ois = new ObjectInputStream(fis);
// reading object's value and casting ArrayList<Customer>
listOfFaculty = (ArrayList<Faculty>)ois.readObject();
}
catch (FileNotFoundException fnfex) {
fnfex.printStackTrace();
}
catch (IOException ioex) {
ioex.printStackTrace();
}
catch (ClassNotFoundException ccex) {
ccex.printStackTrace();
}
for(Faculty stud : listOfFaculty){
System.out.println(stud.getName());
}
}
}