woo boy, crazy day today
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
<!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<Employee> employees = new ArrayList<Employee>();
|
||||
|
||||
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<Employee> arr) {
|
||||
for (int i = 0; i < arr.size() - 1; ++i) {
|
||||
for (int j = i+1; j < arr.size(); ++j)
|
||||
if (arr.get(i).computePay() < 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 < arr.length - 1; ++i) {
|
||||
for (int j = i+1; j < arr.length; ++j)
|
||||
if (arr[i].computePay() < arr[j].computePay()) {
|
||||
Employee temp = arr[i];
|
||||
arr[i] = arr[j];
|
||||
arr[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Company{" + "employees=" + employees + '}';
|
||||
}
|
||||
|
||||
public static void print(Employee[] arr) {
|
||||
for(Employee e: arr) {
|
||||
System.out.println(e);
|
||||
System.out.println("-----------------------");
|
||||
}
|
||||
}
|
||||
|
||||
public static void print(Object[] arr) {
|
||||
for (Object e: arr) {
|
||||
if (e instanceof Employee)
|
||||
System.out.println(e + " " + ((Employee) e).computePay());
|
||||
System.out.println("-----------------------");
|
||||
}
|
||||
}
|
||||
/*
|
||||
public static void main(String[] args) {
|
||||
SalaryEmployee se1 = new SalaryEmployee(50000, "john", new Date());
|
||||
SalaryEmployee se2 = new SalaryEmployee(60000, "mary", new Date());
|
||||
WageEmployee we1 = new WageEmployee(20, 150, "paul", new Date());
|
||||
WageEmployee we2 = new WageEmployee(20, 150, "anna", new Date());
|
||||
|
||||
ArrayList<Employee> list = new ArrayList<>();
|
||||
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, "Mary Poppins", new GregorianCalendar(1990, 12, 18).getTime()));
|
||||
c.addToGroup(new WageEmployee(12, 160, "John Wayne", new GregorianCalendar(1920, 11, 2).getTime()));
|
||||
c.addToGroup(new SalaryEmployee(70000, "Marylyn Monroe", new GregorianCalendar(1920, 11, 2).getTime()));
|
||||
c.addToGroup(new Manager(40000, "Brad Pitt", new GregorianCalendar(1920, 11, 2).getTime()));
|
||||
System.out.println(c);
|
||||
System.out.println("------------------------------------");
|
||||
Company.print(c.employees.toArray());
|
||||
System.out.println("------------------------------------");
|
||||
System.out.println("sort by salary");
|
||||
Company.sortBySalary(c.employees);
|
||||
Company.print(c.employees.toArray());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
Reference in New Issue
Block a user