I'm making a program to simulate patients and the severity of their illness.
I'm having trouble with adding different instances of one class to another class.
For some reason, when I use a while loop, it ultimately only makes one instance.
Here is my code:
while(myScan.hasNext()){
String line = myScan.nextLine();
String [] storage = line.split(",");
int severity = Integer.parseInt(storage[1]);
Patient x = new Patient(storage[0],severity);
Priority.add(x);
}
When I make each instance separately and print my "Priority" class, it works fine. But when using the while loop, it only prints out the last instance, as if it is getting overwritten.
For Example:
Patient p1 = new Patient(name1,1);
Patient p2 = new Patient(name2,2);
Patient p3 = new Patient(name3,3);
This will work fine. but not when using the while loop to read from a file. It will only print p3.