-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadFile.java
163 lines (119 loc) · 3.39 KB
/
ReadFile.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
package rebuilt;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class ReadFile
{
private File input;
private ArrayList<String[]> raw;
private String date;
private int testType;
private int totalNumber;
private ArrayList<Student> students;
public static final int[] MAX_MC = {39, 20, 15};
public static final int[] MAX_FR = {45, 25, 15};
public ReadFile(String filePath)
{
input = new File(filePath);
}
public void process()
{
try
{
BufferedReader reader = new BufferedReader(new FileReader(input));
String dataRow = reader.readLine();
raw = new ArrayList<String[]>();
while (dataRow != null)
{
raw.add(dataRow.split(","));
dataRow = reader.readLine();
}
reader.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
/**
* Parses all student information as well as checks if information is valid
* @throws IllegalArgumentException
*/
public void parse() throws IllegalArgumentException
{
students = new ArrayList<Student>();
//get date
date = raw.get(0)[1];
//get test type
testType = Integer.parseInt(raw.get(1)[1]);
//check test type
if( !(testType == 0 || testType == 1 || testType == 2))
{
throw new IllegalArgumentException("Test Type is set incorrectly!");
}
//get total number of multiple choice in test
totalNumber = Integer.parseInt(raw.get(2)[1]);
//check if totalNumber is valid
if(!(totalNumber > 0 && totalNumber <= MAX_MC[testType]))
{
throw new IllegalArgumentException("Total Number of Multiple Choice is set incorrectly!");
}
//parse student information
for(int i = 0; i < raw.size() - 5; i++)
{
String name = raw.get(i+5)[0];
int MC = Integer.parseInt(raw.get(i+5)[1]);
int FR = Integer.parseInt(raw.get(i+5)[2]);
students.add(new Student(name, MC, FR));
}
//check multiple choice and free response scores
for(int i = 0; i < students.size(); i++)
{
int mc = students.get(i).getRawMCScore();
int fr = students.get(i).getRawFRScore();
if(mc > totalNumber)
{
throw new IllegalArgumentException(students.get(i).getName() + " has an MC score larger than the total Number of MC!");
}
else if(mc <= 0)
{
throw new IllegalArgumentException(students.get(i).getName() + " has an MC score less than or equal to 0!");
}
if(fr > MAX_FR[testType])
{
throw new IllegalArgumentException("Student at index " + (i+6) + " has an FR score greater than the maximum!");
}
else if(fr < 0)
{
throw new IllegalArgumentException("Student at index " + (i+6) + " has an FR score less than 0!");
}
}
}
public ArrayList<String[]> getRaw()
{
return raw;
}
public ArrayList<Student> getStudentList()
{
return students;
}
public String getDate()
{
return date;
}
public int getTestType()
{
return testType;
}
public int getNumberOfMultipleChoice()
{
return totalNumber;
}
}