title: How to set a value of a variable of an object in an ArrayList
body: <p>I am working on an assignment in which I have to:</p>
  
  <ol>
  <li><p>Create an Employee class with the following attributes/variables:
  name
  age
  department</p></li>
  <li><p>Create a class called Department which will contain a list of employees.</p>
  
  <p>a. Department class will have a method which will return its employees ordered by age.</p>
  
  <p>b. Value of Department can be only one of the following:</p>
  
  <ul>
  <li>"Accounting"</li>
  <li>"Marketing"</li>
  <li>"Human Resources"</li>
  <li>"Information Systems"</li>
  </ul></li>
  </ol>
  
  <p>I am having the hardest time trying to figure out how to complete 2b.
  Here is what I have so far:</p>
  
  <pre><code>import java.util.*;
  
  public class Employee {
  String name; 
  int age;
  String department;
  
  Employee (String name, int age, String department) {
      this.name = name;
      this.age = age;
      this.department = department;
  
  }
  int getAge() {
      return age;
  }
  }
  
  class Department {
  public static void main(String[] args) {
      List&lt;Employee&gt;empList = new ArrayList&lt;Employee&gt;();
  
      Collections.sort (empList, new Comparator&lt;Employee&gt;() {
          public int compare (Employee e1, Employee e2) {
              return new Integer (e1.getAge()).compareTo(e2.getAge());
          }
      });
      }
  }   
  </code></pre>