-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java~
More file actions
115 lines (81 loc) · 2.97 KB
/
Copy pathStudent.java~
File metadata and controls
115 lines (81 loc) · 2.97 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
import java.io.*;
import java.util.List;
import java.util.ArrayList;
class Student
{
private String name, var1, var2, var3, courseN;
private int val2, val3;
private double overall;
private List <Mark> assignments;
public Student ( String theName )
{
this.name = theName;
assignments = new ArrayList <Mark>();
}
public void createAssignmentsList(String coN) throws IOException {
//Reads file and assign each mark
BufferedReader studFile = new BufferedReader(new FileReader (coN + "/" + name + ".txt"));
while(true)
{
var1 = studFile.readLine();
if(var1==null){break;}
var2 = studFile.readLine();
val2 = Integer.parseInt(var2);
var3 = studFile.readLine();
val3 = Integer.parseInt(var3);
Mark m = new Mark(var1, val2, val3);
assignments.add(m);
}
courseN = coN;
studFile.close(); //Close File
}
public String getStudentName()
{
return this.name;
}
public void setStudentName( String newName )
{
this.name = newName;
}
///////////////////////////// Students Marks //////////////////////////////////
//SHOW Assignments LIST
public void showAssignments(){
for(int i=1; i < assignments.size();i++){
Output.println("[" + i + "]" + assignments.get(i).getAssignment());
}
}
//SHOW SUMMARIZED MARKS
public double showOverall(){
for(int i=1; i < assignments.size();i++){
overall = overall + assignments.get(i).getPercentage();
}
overall = overall/(assignments.size()-1);
overall = Math.round(overall*Math.pow(10, 2))/Math.pow(10, 2); //Rounding percentage to two decimal places
return overall;
}
//CREATE NEW ASSIGNMENT
public void createAssignment(Mark k) throws IOException
{
//Add assignment to student file
PrintWriter studeFile = new PrintWriter(new FileWriter (courseN + "/" + name + ".txt",true));
studeFile.println(k.getAssignmentName());
studeFile.println(k.getAssignmentTotal());
studeFile.println(k.getAssignmentScore());
studeFile.close();
assignments.add(k);//add assignment at the end of the list
} // END NEW ASSIGNMENT
//DELETE ASSIGNMENT
public void deleteAssignment(int index) throws IOException
{
assignments.remove(index); //removes student object form the list
//Put new array to the file
PrintWriter delAssignmentFile = new PrintWriter(new FileWriter (courseN + "/" + name + ".txt"));
for(int j = 0; j < assignments.size(); j++)
{
delAssignmentFile.println(assignments.get(j).getAssignmentName());
delAssignmentFile.println(assignments.get(j).getAssignmentTotal());
delAssignmentFile.println(assignments.get(j).getAssignmentScore());
}
delAssignmentFile.close();
}// END OF DELETE ASSIGNMENT
}