-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileReader.java
More file actions
48 lines (42 loc) · 1.32 KB
/
Copy pathFileReader.java
File metadata and controls
48 lines (42 loc) · 1.32 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
//--== CS400 File Header Information ==--
//Name: Ryan Szymanski
//Email: rpszymanski@wisc.edu
//Team: BA
//TA: BRIANNA COCHRAN
//
//Lecturer: Florian
//Notes to Grader:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
/**
* Class that creates a new HashTable of student based on an input of a text file that has student
* data on it
*
* @author rpszy
*
*/
public class FileReader {
public FileReader(HashTableMap map, File file) throws FileNotFoundException {
Scanner sc = new Scanner(file);
while (sc.hasNextLine()) {
String line = sc.nextLine();
String[] arrOfStu = line.split(",");
if (arrOfStu.length > 3 || arrOfStu.length < 2) { // NOTE: typo? Should be ||.
//Also, put this BEFORE the previous 3 lines to prevent index out of bounds exception
continue;
}
arrOfStu[0] = arrOfStu[0].trim();
arrOfStu[1] = arrOfStu[1].trim();
arrOfStu[2] = arrOfStu[2].trim();
try {
int IDNum = Integer.parseInt(arrOfStu[0].trim());
Student stu = new Student(IDNum, arrOfStu[1], arrOfStu[2]);
map.put(stu.getID(), stu);
} catch (NumberFormatException e) {
continue;
}
}
sc.close();
}
}