<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Company.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
table {color: #888888; background-color: #313335; font-family: monospace}
.comment {color: #808080}
.whitespace {color: #505050}
.ST0 {color: #808080; font-family: monospace; font-weight: bold}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/lab5_CalebFontenot/src/main/java/com/calebfontenot/test/Company.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.calebfontenot.test;

<span class="literal">import</span> java.util.ArrayList;
<span class="literal">import</span> java.util.Date;
<span class="literal">import</span> java.util.GregorianCalendar;

<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">caleb</span>
 <span class="comment">*/</span>
public class Company {
    
    private ArrayList&lt;Employee&gt; employees = new ArrayList&lt;Employee&gt;();
    
    public boolean addToGroup(Employee e) {
        employees.add(e);
        return true;
    }
    
    public boolean removeFromGroup(Employee e) {
        if (employees.contains(e)) {
            employees.remove(e);
            return true;
        } else {
            return false;
        }
    }
    
        public static void sortBySalary (ArrayList&lt;Employee&gt; arr) {
        for (int i = 0; i &lt; arr.size() - 1; ++i) {
            for (int j = i+1; j &lt; arr.size(); ++j)
                if (arr.get(i).computePay() &lt; arr.get(j).computePay()) {
                    Employee temp = arr.get(i);
                    arr.set(i, arr.get(j)) ;
                    arr.set(j, temp);
                }
        }
    }
    
    public static void sortBySalary (Employee arr[]) {
        for (int i = 0; i &lt; arr.length - 1; ++i) {
            for (int j = i+1; j &lt; arr.length; ++j)
                if (arr[i].computePay() &lt; arr[j].computePay()) {
                    Employee temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
        }
    }

    @Override
    public String toString()
    {
        return &quot;Company{&quot; + &quot;employees=&quot; + employees + &#39;}&#39;;
    }
   
    public static void print(Employee[] arr) {
        for(Employee e: arr) {
            System.out.println(e);
            System.out.println(&quot;-----------------------&quot;);
        }
    }
    
    public static void print(Object[] arr) {
        for (Object e: arr) {
            if (e instanceof Employee)
                System.out.println(e + &quot; &quot; + ((Employee) e).computePay());
            System.out.println(&quot;-----------------------&quot;);
        }
    }
    /*
public static void main(String[] args) {
        SalaryEmployee se1 = new SalaryEmployee(50000, &quot;john&quot;, new Date());
        SalaryEmployee se2 = new SalaryEmployee(60000, &quot;mary&quot;, new Date());
        WageEmployee we1 = new WageEmployee(20, 150, &quot;paul&quot;, new Date());
        WageEmployee we2 = new WageEmployee(20, 150, &quot;anna&quot;, new Date());
        
        ArrayList&lt;Employee&gt; list = new ArrayList&lt;&gt;();
        list.add(se1);
        list.add(se2);
        list.add(we1);
        list.add(we2);
        System.out.println(list);
        
        Employee[] ar = new Employee[4];
        ar[0] = se1;
        ar[1] = se2;
        ar[2] = we1;
        ar[3] = we2;
        
        print(ar);
        sortBySalary(ar);
        print(ar);
    }
*/
    public static void main(String[] args)
    {
        Company c =new Company();
       c.addToGroup(new WageEmployee(10, 160, &quot;Mary Poppins&quot;, new GregorianCalendar(1990, 12, 18).getTime()));
       c.addToGroup(new WageEmployee(12, 160, &quot;John Wayne&quot;, new GregorianCalendar(1920, 11, 2).getTime()));
       c.addToGroup(new SalaryEmployee(70000, &quot;Marylyn Monroe&quot;, new GregorianCalendar(1920, 11, 2).getTime()));
       c.addToGroup(new Manager(40000, &quot;Brad Pitt&quot;, new GregorianCalendar(1920, 11, 2).getTime()));
        System.out.println(c);
        System.out.println(&quot;------------------------------------&quot;);
       Company.print(c.employees.toArray());
        System.out.println(&quot;------------------------------------&quot;);
        System.out.println(&quot;sort by salary&quot;);
       Company.sortBySalary(c.employees);
       Company.print(c.employees.toArray());
       
    }
}

</pre></body>
</html>