-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatientReader.java
More file actions
51 lines (35 loc) · 1.37 KB
/
PatientReader.java
File metadata and controls
51 lines (35 loc) · 1.37 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
//package readingFiles;
import java.io.*;
import java.util.*;
public class PatientReader {
//initialize an array list, for storing the patients
private static ArrayList<Patient> patientsList = new ArrayList<Patient>();
public static void readPatients() throws IOException {
//connect the program with the text file for reading.
File file = new File("patients.txt");
Scanner readFile = new Scanner(file);
StringTokenizer token = null;
//initialize the variables that you will need to instantiate the object (Patient)
String fullName="";
int age=0;
double weight=0;
String illness="";
while(readFile.hasNextLine()) {
token = new StringTokenizer(readFile.nextLine(), ",");
//use the information from one line to initialize the variables needed to instatiate the object
fullName = token.nextToken();
age = Integer.parseInt(token.nextToken());
weight = Double.parseDouble(token.nextToken());
illness = token.nextToken();
Patient patient = new Patient( fullName, age, weight, illness);
patientsList.add(patient);
//System.out.println(patient.toString());
}
}
public static void main(String[] args) throws IOException {
readPatients();
for(Patient patient: patientsList) {
System.out.println(patient);
}
}
}