title: How do I make a class to dynamic check different objects variable?
body: <p>I'm new to Java, and i'm trying to create an automatic working shift schedule.</p>
  <p>I want the code to mix four different employees to handle a morning shift and afternoon shift every work day.
  I have made some code that just pick a random employee into a shift:</p>
  <pre><code>import java.util.Arrays;
  import java.util.Random;
  
  public class CreateNewShift {
  
      public static void main(String[] args) {
          
          int startWeek = 30; //Which week would start from?
          int endWeek = 32; //which week will you end on?
          generateShift(startWeek, endWeek);
  
      }
  
      private static void generateShift(int startWeek, int endWeek) {
  
          String Employees[] = {&quot;Employee1&quot;, &quot;Employee2&quot;, &quot;Employee3&quot;, &quot;Employee4&quot;};
          String morningShift;
          String afternoonShift;
  
        for (int x = 0; x &lt;= (endWeek - startWeek); x++) { //This is counting the number of weeks
           System.out.println(&quot;\nWeek: &quot; + (startWeek+x));
  
        for (int i = 1; i &lt;= 5; i++) {   //this is finding the next working shift day
            morningShift = p.chooseRandomEmployee(Employees);
            afternoonShift = p.chooseRandomEmployee(Employees);
            if (i == 1) {
              System.out.println(&quot;Mon: &quot; + morningShift + &quot; + &quot; + afternoonShift);
            }
            else if (i == 2) {
              System.out.println(&quot;Tue: &quot; + morningShift + &quot; + &quot; + afternoonShift);
            }
            else if (i == 3) {
               System.out.println(&quot;Wed: &quot; + morningShift + &quot; + &quot; + afternoonShift);
            }
            else if (i == 4) {
              System.out.println(&quot;Thu: &quot; + morningShift + &quot; + &quot; + afternoonShift);
            }
            else {
              System.out.println(&quot;Fri: &quot; + morningShift + &quot; + &quot; + afternoonShift);
            }
          }
        }
      }
  
  
  
  public class Employee {
    public String chooseRandomEmployee(String[] Employees) {
          Random r = new Random();
          int randomNumber = r.nextInt(Employees.length);
          return Employees[randomNumber];
    }
  }
  </code></pre>
  <p>However, I now want the code to handle more restictions.
  So i'm currently trying to add the option for the employees to choose some specific days that they dont want to have a shift. I have done this by adding this code to the Employee class:</p>
  <pre><code>public class Employee {
    boolean monShift = true;
    boolean tueShift = true;
    boolean wedShift = true;
    boolean thuShift = true;
    boolean friShift = true;
  
    public String chooseRandomEmployee(String[] Employees) {
          Random r = new Random();
          int randomNumber = r.nextInt(Employees.length);
          return Employees[randomNumber];
    }
  }
  </code></pre>
  <p>And then i had tried to create new objects in my main class:</p>
  <pre><code>private static void generateShift(int startWeek, int endWeek) {
          Employee Employee1 = new Employee(&quot;Employee1&quot;);
          Employee Employee2 = new Employee(&quot;Employee2&quot;);
          Employee Employee3 = new Employee(&quot;Employee3&quot;);
          Employee Employee4 = new Employee(&quot;Employee4&quot;);
          String Employees[] = {&quot;Employee1&quot;, &quot;Employee2&quot;, &quot;Employee3&quot;, &quot;Employee4&quot;};
          String morningShift;
          String afternoonShift;
          ....
  </code></pre>
  <p>Quetions:</p>
  <p>How can I improve my code in the Employee class to do a check if the random chosen employee have</p>
  <pre><code>monShift = true;
  </code></pre>
  <p>I have tried something like this, but i know it will not work, (and does not work either):</p>
  <pre><code>import java.util.Random;
  
  public class Employee {
      public String chooseRandomEmployee(String[] Employees) {
          Random r = new Random();
          int randomNumber = r.nextInt(Employees.length);
          **if ((&quot;Employee&quot; + randomNumber).monShift == false) {**
             // Go back and try find a new random employee
          }
          else {
            return Employees[randomNumber];
          }
      }
  }
  </code></pre>
  <p>So i need a way to make my code dynamic to know which object (employee) it has to check if they are available that specific day or not.</p>
  <p>Feel free to ask for a deepening if my question is not clear.</p>
  <p>Since this i my first question on this forum, I also appriciate feedback if my question and thoughts are too long, or any other comments.</p>