skittels
skittels

Reputation: 5

Adding Data separately to all objects in an arraylist

I'm stuck at the moment on a problem, I'm trying to add data separately to all objects in an array list.

eg. Daily, I want to be able to add how much medication each patient has taken to their record in the arraylist. Each patient has a unique identifier which is whats in the arraylist.

I was wondering using JOptionPane is it possible to pull up each patient separately, so that after one is entered the next shows up to enter in information and how would I go about doing it?

Thanks!

Upvotes: 0

Views: 46

Answers (1)

Ozgen
Ozgen

Reputation: 1092

Pseduo code of the data structure might be as following :

class Patient{

   String patientId;
   List<Medication> list;

   public addMedication(Medication med){
      list.add(med); 
   }

}

class Medication{
   String name;
   ...
}



class PatientManager{

   Map<String,Patient> map;

   public addMedication(String patientId,Medication med){
      map.get(patientId).addMedication(med);

   }

}

Upvotes: 1

Related Questions