-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudent.java
63 lines (58 loc) · 2.13 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
import java.io.*;
import java.util.*;
/**
* Student class
*
* Stores the name of the Student's text file
* When a student object is made, the student's text file
* is also made
*
* There are methods in this class that deal with deleting the student account,
* outputting the student menu, and getting the arrayList of Submission objects
*
* @author Yu Hyun Kim
* @version 12/12/21
*/
public class Student extends People implements Serializable {
/**
* Constructor for Student object
* @param name name of the student
* @param email email of the student
*/
public Student(String name, String email) {
super(name, email);
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(super.getTextFileName()))) {
ArrayList<Submission> studentSubmission = new ArrayList<>();
oos.writeObject(studentSubmission);
} catch (Exception e) {
//catch exception
}
}
/**
* Method returns the arrayList of all submission in student's txt file
* @return ArrayList of all submission objects of that student
*/
public ArrayList<Submission> getSubmissionListInFile() {
try (ObjectInputStream oos = new ObjectInputStream(new FileInputStream(super.getTextFileName()))) {
Object o = oos.readObject();
if (o == null) {
return null;
}
ArrayList<Submission> theSubs = (ArrayList<Submission>) o;
return theSubs;
} catch (Exception e) {
return null;
}
}
/**
* Method puts the new submission arrayList into student's txt file and saves it
* @param newArrayList the updated ArrayList of Submission objects to be written into the student's file
*/
public void updateSubmissionListInFile(ArrayList<Submission> newArrayList) {
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(super.getTextFileName()))) {
oos.writeObject(newArrayList);
} catch (Exception e) {
//catch exception
}
}
}