title: Creating an array of objects by parameters
body: <p>I have 2 classes, the first class (PatientFlow) contains a constructor, a bunch of getMethods and a toString, no main. The first class cannot output or get read input, only through passed parameters.
  The second class (Patient) asks for the users inputs for some questions such as name, dob etc.. this class runs a bunch of methods aswell.</p>
  <pre><code>Patient p1 = new Patient(name,dob,address,gender,medicareNum,appDay,time); //Patient created
  //is what is created with all users input and sent to the constructor class
  </code></pre>
  <p>Now my task is to create an array of patient(objects) within the first class (patientFlow).. but I don't understand how to do that... I've been seriously stuck on this for some days now and its driving me insane.. When I put the main() in the first class, I can't reference anything because of static..</p>
  <pre><code>public class Patient
  {
    private String name, age, address, gender, time, appDay;
    private int medicareFinal;
    private boolean vaccination;
    public Patient (String name, String age, String address, String gender, int medicareFinal, String appDay, String time)
      {
      this.name = name;
      this.age = age;
      this.address = address;
      this.gender = gender;
      this.medicareFinal = medicareFinal;
      this.appDay = appDay;
      this.time = time; 
      }
    public String getName()
      { 
       return name;
      }
    public String getAddress()
      { 
       return address;
      }
    public String getGender()
      { 
       return gender;
      }
    public String getTime()
      { 
       return time;
      }
    public String getAge()
      {
       return age; 
      }
    public int getMedicare()
      {
       return medicareFinal;
      }
    public String getAppDay()
      {
       return appDay;
      }
    public String toString()
      { 
       String data; 
       data = &quot;Patient Name: &quot;+ name + &quot;\n&quot;;
       data += &quot;Age/Dob: &quot; + age + &quot;\n&quot;;
       data += &quot;Address: &quot; + address + &quot;\n&quot;;
       data += &quot;Gender: &quot; + gender + &quot;\n&quot;;
       data += &quot;Medicare Number: &quot; + medicareFinal + &quot;\n&quot;;
       data += &quot;Appointment Day: &quot; + appDay + &quot;\n&quot;;
       data += &quot;Appointment Time: &quot; + time + &quot;\n&quot;;
       return data;
      }
  }
  
  import java.time.*; // This is used to utilize dates/times
  import java.util.*;
  public class PatientFlow
  {
     Patient p1, p2;
     Scanner scan=new Scanner(System.in); 
     enum weekdays {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday} //enumerated type for Task 4    
     public void readPatient1() //Details of first patient
       {
        System.out.println(&quot;Firstly, what is your full name?&quot;);
        String name = scan.nextLine(); 
        System.out.println(name + &quot;, Please enter your date of birth in the correct format yyyy-mm-dd:&quot;);
        String dob = scan.nextLine();
        age(dob); //Calling age method to check if patient is older than 18
        System.out.println(&quot;What is your current residential address?&quot;); 
        String address= scan.nextLine();
        System.out.println(&quot;Are you male or female?&quot;);
        String gender = scan.nextLine();
        System.out.println(&quot;What is your 8-digit Medicare number?&quot;);
        int medicareNum = scan.nextInt();
        int medicareFinal = medicare(medicareNum); //Calling medicare method to check if input = 8 numbers
        String shift = scan.nextLine();
        System.out.println(&quot;What day would you like to book the vaccination?&quot;);
        String appDay = scan.nextLine();
        weekdays(appDay); //Calling weekday method which checks availability through enumerated type
        System.out.println(&quot;What time would you like to book on &quot; + appDay + &quot;?&quot;);
        String time = scan.nextLine();
        p1 = new Patient(name,dob,address,gender,medicareNum,appDay,time); //Patient created
        System.out.println(&quot;You have booked in:&quot;);
        System.out.println(&quot;-----------------------------------------------&quot; + &quot;\n&quot; + p1);
        System.out.println(&quot;-----------------------------------------------&quot;);
       }
     public void readPatient2() //Details for the second patient
       {
        System.out.println(&quot;Name of the person attending the second booking:&quot;);
        String name = scan.nextLine(); 
        System.out.println(name + &quot;, Please enter your date of birth in the correct format yyyy-mm-dd:&quot;);
        String dob = scan.nextLine();
        age(dob); //Calling age method to check if patient is older than 18
        System.out.println(&quot;What is your current residential address?&quot;); 
        String address= scan.nextLine();
        System.out.println(&quot;Are you male or female?&quot;);
        String gender = scan.nextLine();
        System.out.println(&quot;What is your 8 digit medicare number?&quot;);
        int medicareNum = scan.nextInt();
        int medicareFinal = medicare(medicareNum); //Calling medicare method to check if input = 8 numbers
        String shift = scan.nextLine(); //Using this to catch the users 'enter' input
        System.out.println(&quot;What day would you like to book the vaccination?&quot;);
        String appDay = scan.nextLine();
        weekdays(appDay); //Calling weekday method which checks availability through enumerated type
        System.out.println(&quot;What time would you like to book on &quot; + appDay + &quot;?&quot;);
        String time = scan.nextLine();
        p2 = new Patient(name,dob,address,gender,medicareNum,appDay,time); //Patient created
        System.out.println(&quot;Thank you for using this online booking service.&quot;);
        System.out.println(&quot;You have booked in:&quot;);
        System.out.println(&quot;-----------------------------------------------&quot; + &quot;\n&quot; + p2);
        System.out.println(&quot;-----------------------------------------------&quot;);
       }
     public void age(String dob) //Method for DOB
       {
        Scanner scan = new Scanner(System.in); //Retrieving User inputs
        String answer, consent;
        LocalDate dateOfBirth = LocalDate.parse(dob); // Convert string input to date format
        LocalDate currDate = LocalDate.now(); // Get todays date: yyyy-mm-dd
        Period period = Period.between(currDate, dateOfBirth); // Get the difference between the two dates
        int age  = Math.abs(period.getYears()); // Isolate the number of years to get proper age format
        if (age &lt; 18)
        {
          System.out.println(&quot;Sorry, because you are &quot; + age + &quot; years old, it is illegal to book you an appointment. You must be 18 to book this service.&quot;);
          System.out.println(&quot;If an adult is with you, type 'yes' to continue. If not, try booking again later. Thank you&quot;);
          answer = scan.nextLine();
          if (answer.equals(&quot;yes&quot;))
          {
            System.out.println(&quot;Continuing booking process...&quot;);
          } else
          {
            System.out.println(&quot;You need an adult with you in order to continue this booking.&quot;);
            System.exit(0);   //Terminates if person is under 18 without adult
          }
        } //returning values
       }
     public static int medicare(int medicareNum) //Method for medicare
       {
         Scanner scan = new Scanner(System.in);
         String correct, shift;
         int medicareFinal = medicareNum;
         int medicaretemp;
         int length = String.valueOf(medicareNum).length(); // Int conversion to string length
         if (length == 8) // If statement to proceed with correct detail
         {
           System.out.println(medicareNum +&quot;, Are you sure this is the correct number? This information is very important. 'yes' or 'no'&quot;);
           correct = scan.nextLine();
           if (correct.equals(&quot;yes&quot;)) // Nested if statement
           {                     
             System.out.println(&quot;Thank you, please continue with the booking&quot;);
             medicareFinal = medicareNum;
           } else
           {
             length = 0;
           }
         }
         while (length != 8) // while loop to get correct size of input 
          {   System.out.println(&quot;You haven't input the correct amount of numbers in. Please try again.&quot;);
              medicaretemp = scan.nextInt();
              medicareFinal = medicaretemp;
              shift = scan.nextLine(); //Using this to catch the users 'enter' input
              int lengthNew = String.valueOf(medicaretemp).length(); // Conversion of int to String
              if (lengthNew == 8)
              {
                System.out.println(medicaretemp +&quot;, Is this new number correct? This information is very important. 'yes' or 'no'&quot;);
                correct = scan.nextLine();
                if (correct.equals(&quot;yes&quot;))
                {
                  medicareFinal = medicaretemp;
                  System.out.println(&quot;Thank you, please continue with the booking&quot;);
                  break; //Breaking loop if requirement is met
                } else
                {
                  length = 0;
                }
              }
          } 
          return medicareFinal; // return value
      }
     public void weekdays(String appDay)
       {    
        boolean dayAvail = false;
        for(weekdays day : weekdays.values())
           {
            if (appDay.equalsIgnoreCase(day.name())) 
            {
              dayAvail = true;
              System.out.println(appDay + &quot; is available for your appointment.&quot;);
              break;
            }
           }
        if (!dayAvail)
        {
          System.err.println( &quot;This day is not available..&quot; ); // Shows error message, will put exception in there for Assignment 3      
        } 
       }
     public void confirmation()
       {
        int answer;
        String shift;
        System.out.println(&quot;Are the details correct for both patients or do they need modifying?&quot;);
        System.out.println(&quot;Press '1' to modify &quot; + p1.getName() + &quot;, press '2' to modify &quot; + p2.getName() + &quot;, or press 3 to complete booking&quot;);
        answer = scan.nextInt();
        shift = scan.nextLine(); //Using this to catch the users 'enter' input
        if (answer==1)
        {
          readPatient1(); //Calls back to Patient 1 method
          confirmation();
        }
        if (answer==2)
        {
          readPatient2(); //Calls back to Patient 2 method
          confirmation();
        }
        if (answer==3)
        {
          System.out.println(&quot;Thank you for using this online booking service.&quot;);
          System.out.println(&quot;You have booked in:&quot;);
          System.out.println(&quot;-----------------------------------------------&quot; + &quot;\n&quot; + p1);
          System.out.println(&quot;-----------------------------------------------&quot; + &quot;\n&quot; + p2);
          System.out.println(&quot;-----------------------------------------------&quot;);
          System.out.println(&quot;Remember to come 10 minutes early and sign in with the appropriate applications! Both appointments will be held at the AIS&quot;);
          System.exit(0); //Exit program when user is happy with details
        }
       }
     public void PatientBook()
       {
        String answer;
        System.out.println(&quot;\n&quot;);
        System.out.println(&quot;Would you like to add another appointment? 'yes' or 'no'&quot;);
        answer = scan.nextLine();
        switch (answer) //Using a switch to dictate which methods are required next
          {
            case (&quot;yes&quot;):
                readPatient2();
                confirmation();
            case (&quot;no&quot;):
                  System.out.println(&quot;Thank you for using this online booking service.&quot;);
           System.out.println(&quot;You have booked in:&quot;);
           System.out.println(&quot;-----------------------------------------------&quot; + &quot;\n&quot; + p1);
           System.out.println(&quot;-----------------------------------------------&quot;);
           System.out.println(&quot;Remember to come 10 minutes early and sign in with the appropriate applications! Your appointment will be held at the AIS&quot;);
           System.exit(0);
          }
       }
     public void init() //method to call all methods when required
       {
        start();
        readPatient1();
        PatientBook();
        readPatient2();
        confirmation();
       }
     public static void main(String [] args)
       {
        PatientFlow pf = new PatientFlow(); //Creating the object
        pf.init();
       }
  }
  </code></pre>
  <p>How can I fix this?</p>