-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAssessment.java
More file actions
61 lines (55 loc) · 1.68 KB
/
Assessment.java
File metadata and controls
61 lines (55 loc) · 1.68 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
/*
*
*This is a porgram that computes for
*
*
*
*
*/
import java.util.*;
import java.io.*;
import javax.swing.*;
import java.lang.*;
public class Assessment { //Main Class
public static void main(String[] args) throws IOException {
ArrayList<Student> stud = new ArrayList<Student>();
Scanner read;
String idNum = "";
try {
read = new Scanner(new File("students.txt"));
while (read.hasNextLine()) {
String lineOfText = read.nextLine();
String[] data= lineOfText.split(",");
idNum = data[0];
String lastName = data[1];
String firstName = data[2];
char initial = data[3].charAt(0);
String course = data[4];
int year = Integer.parseInt(data[5]);
double balance = Double.parseDouble(data[6]);
double prelims = Double.parseDouble(data[7]);
double midterms = Double.parseDouble(data[8]);
double finals = Double.parseDouble(data[9]);
stud.add(new Student(idNum, lastName, firstName, initial, course, year, balance, prelims, midterms, finals));
}
} catch (FileNotFoundException e) {
System.out.print("File not found.");
}
boolean found = true;
while (found) {
String idNumber = JOptionPane.showInputDialog(null, "Enter ID number", "Assessment", JOptionPane.OK_CANCEL_OPTION); //a GUI prompt that makes a dialog box
if (idNumber.isEmpty()) {
JOptionPane.showMessageDialog(null, "ID Number not found.", "Error", JOptionPane.ERROR_MESSAGE);
found = true;
} else {
for (int i = 0; i < stud.size(); i++) {
if (idNumber.equals(stud.get(i).getIDnum())) {
Object[] f = {stud.get(i).toString()};
JOptionPane.showMessageDialog(null,f,"Summary",1);
}
}
found = false;
}
}
}
}