-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentTracker.java
More file actions
55 lines (43 loc) · 1.36 KB
/
StudentTracker.java
File metadata and controls
55 lines (43 loc) · 1.36 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
/**
* ITEC 3150 - 01 Spring 2026
* IC 1
*/
package School.al;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
public class StudentTracker {
private ArrayList<Student> students = new ArrayList<>();
public static void main(String[] args) {
StudentTracker tracker = new StudentTracker();
if (tracker.readFile()) {
tracker.printStudents();
}
}
// TODO: MODIFY THIS METHOD ONLY - THIS IS THE ONE YOU WILL SUBMIT
private boolean readFile() {
try (DataInputStream read = new DataInputStream(new FileInputStream("Students.dat"))){
while(true){
int id = read.readInt();
String name = read.readUTF();
double gpa = read.readDouble();
addStudent(new Student(id, name, gpa));
}
} catch (EOFException e){
return true;
} catch (IOException e){
return false;
}
// Replace this with binary reading from Students.dat
}
private void addStudent(Student s) {
students.add(s);
}
private void printStudents() {
for (Student s : students) {
System.out.println(s);
}
}
}