1

So I am making a project and I want to create a new clinic.

On my UI we insert all the topics that we need to create the clinic and they must be saved as ArrayList and I am struggling with this method.

this is how i am asking for the input, should i change to a scanner?

laboratoryId = Utils.readLineFromConsole("Enter Clinic Id: ");

class to the array

public class ClinicalAnalysisLabStore{

        private ArrayList<ClinicalAnalysisLab> cliniclist;
        
        public ClinicalAnalysisLabStore(){
                cliniclist = new ArrayList<>();
        }

        public ArrayList<ClinicalAnalysisLab> getCliniclist() {
                return cliniclist;
        }

      cals = new ClinicalAnalysisLabStore();
        ArrayList<ClinicalAnalysisLab> cliniclist = cals.getCliniclist();

for(ClinicalAnalysisLab cals : cliniclist){
                    System.out.print(cals.getLaboratoryId()+"\n");
                    System.out.print(cals.getName()+ "\n");
                    System.out.print(cals.getAddress()+"\n");
                    System.out.print(cals.getPhoneNumber()+"\n");
                    System.out.print(cals.getTinNumber()+"\n");
                    System.out.print(cals.getTestType()+"\n");

                }
                Utils.readLineFromConsole("The Operation was a success!");

this is a short cut from my code where i am trying to print the arraylist but it only prints "The Operation was a success!"

18
  • Where did you add variables to the arraylist? Commented May 9, 2021 at 0:01
  • public class ClinicalAnalysisLabStore{ private ArrayList<ClinicalAnalysisLab> cliniclist; public ClinicalAnalysisLabStore(){ cliniclist = new ArrayList<>(); } public ArrayList<ClinicalAnalysisLab> getCliniclist() { return cliniclist; } this is the class where i made the array Commented May 9, 2021 at 0:22
  • Although you made the arraylist, you never added any items to it, so the arraylist is empty. Commented May 9, 2021 at 1:06
  • so how do i add items to it? Commented May 9, 2021 at 1:13
  • See my answer posted below Commented May 9, 2021 at 1:16

1 Answer 1

1

You're ArrayList is empty. So, the code is actually working perfectly.

What you'll need to do is add items to the ArrayList.

To add an item:

laboratoryId = Utils.readLineFromConsole("Enter Clinic Id: ");
ClinicalAnalysisLab obj = new ClinicalAnalysisLab(laboratoryId, *name*, *address*, *phoneNumber*, *tinNumber*) {
clinicList.add(obj);

In this case, you would just create the object based on however you want. So, change the variables "name", "address", "phoneNumber", and "tinNumber" with whatever you want.

One example would be:

laboratoryId = Utils.readLineFromConsole("Enter Clinic Id: ");
ClinicalAnalysisLab obj = new ClinicalAnalysisLab(laboratoryId, "First Lab", "32 Lincoln Rd", "666 666 6666, "102") {
clinicList.add(obj);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.