Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding attributes in 2 arraylists
    primarykey
    data
    text
    <p>I have 2 arraylist which the records are stored as objects.<br> First arraylist object has attributes such as patient id , totaltestcost, totaltreatmentcost. Second arraylist object has attributes such as patient id, totalservicecharges.</p> <p>Now my problem is when i try to add up the total, meaning totaltestcost + totaltreatmentcost + totalservicecharges, for a given patient id, i cant add up the total and display it. </p> <p>I found out that that since it is in 2 arrays i need to search the arrays by the id and get the costs.</p> <p>This is the way how i search a patient record public patient_class searchrecord(ArrayList patients, String search) {</p> <pre><code> for(patient_class patient: patients) //used enhanced for loop if(patient.getid().equals(search)) { return patient; } return null; </code></pre> <p>}</p> <p>Is there a possibility which i can modify this code to get the costs stored in 2 arrays ?</p> <p>for example like this :-</p> <p>public int searchrecord(ArrayList patients, String search) {</p> <pre><code> for(patient_class patient: patients) //used enhanced for loop if(patient.getid().equals(search)) { int total= patient.gettotaltestcost + patient.gettotaltreatmentcost } return null; </code></pre> <p>} But if i use the above method ill only be able to get the total of totaltestcost+totaltreatmentcost , i need to obtain the servicechargecost as well but its in another array.</p> <p>So how can i do this ?</p> <p>Thank you for your time.</p> <p>Edit :-</p> <p>Finally i managed to do it guys and here is how i did it :-</p> <p>public String addtotal(ArrayList patients, String search,ArrayListpatient2,String search2) { int total;</p> <pre><code> for(patient_class patient: patients) //used enhanced for loop { if(patient.getid().equals(search)) { for(patient_class patient3: patient2) { if(patient3.getid().equals(search2)) { total=patient.gettreatmentcost()+patient.gettestcost()+patient3.getservicecharge(); return Double.toString(total); } } } } return null; </code></pre> <p>}</p> <p>i passed in both arrays at once.</p> <p>Thanks everyone for sharing your answers , next time ill definitely use treemaps </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload