Test.java
import java.util.*;
public class Test
{
public static void main(String[] args) throws CloneNotSupportedException
{
//test information on website
Employee [] a1 = new Employee[9];
a1[0] = new Staff(“Allen”,”Paita”,”123″,”M”,1959,2,23,50);
a1[1] = new Staff(“Zapata”,”Steven”,”456″,”F”,1964,7,12,35);
a1[2] = new Staff(“Rios”,”Enrique”,”789″,”M”,1970,6,2,40);
a1[3] = new Faculty(“Johnson”,”Anne”,”243″,”F”,1962,4,27,Level.FU,”Ph.D”,”Engineering”,3);
a1[4] = new Faculty(“Bouris”,”William”,”791″,”F”,1975,3,14,Level.AO,”Ph.D”,”English”,1);
a1[5] = new Faculty(“Andrade”,”Christopher”,”623″,”F”,1980,5,2,Level.AS,”MS”,”Physical Education”,0);
a1[6] = new Partime(“Guzman”,”Augusto”,”455″,”F”,1977,8,10,35,30);
a1[7] = new Partime(“Depirro”,”Martin”,”678″,”F”,1987,9,15,30,15);
a1[8] = new Partime(“Aldaco”,”Marque”,”945″,”M”,1988,24,11,20,35);
System.out.println(“A:”);
System.out.println(“—————————————————————“);
for(int i = 0; i<9;i++)
{
System.out.println(a1[i].toString());
}
System.out.println(“—————————————————————-“);
System.out.println(“B: Total Monthly Salary for Partime”);
System.out.println(“—————————————————————-“);
double partimeTotal=0;
for(int i = 0; i<9;i++)
{
if(a1[i] instanceof Partime)
{
partimeTotal=partimeTotal + a1[i].monthlyEarning();
}
}
System.out.println(“The total Monthly Salary for Partime is: $” + partimeTotal);
System.out.println(“—————————————————————-“);
System.out.println(“C: Total Monthly Salary for All Employees”);
System.out.println(“—————————————————————-“);
double total = 0;
for(int i = 0; i<9;i++)
{
total = total + a1[i].monthlyEarning();
}
System.out.println(“The total monthly salary for all employees is: $” + total);
System.out.println(“—————————————————————-“);
System.out.println(“D: Sorted by ID Number “);
System.out.println(“—————————————————————-“);
System.out.println(” ” );
bubbleSort(a1);
for(int i = 0; i<9;i++)
{
System.out.println(a1[i].toString());
}
System.out.println(“—————————————————————-“);
System.out.println(“E: Sorted by Last Name ” );
System.out.println(“—————————————————————“);
bubbleSortbyName(a1);
for(int i = 0; i<9;i++)
{
System.out.println(a1[i].toString());
}
System.out.println(“—————————————————————-“);
System.out.println(“F: Cloning”);
System.out.println(“—————————————————————-“);
Faculty abc = new Faculty(“Johnson”,”Anne”,”243″,”F”,1962,4,27,Level.FU,”Ph.D”,”Engineering”,3);
Faculty xyz = (Faculty)abc.clone();
Education e = new Education(“MS”,”Engineering”,3);
xyz.setE(e);
System.out.println(“Clone: “+xyz.toString());
System.out.println(“Original: ” + abc.toString());
System.out.println(“—————————————————————-“);
}
/**
* bubble sort will call compareTo or Comparable to compare by ID number
* @param a1 will be the array with all your Employees
*/
public static void bubbleSort(Employee[] a1) {
boolean swapped = true;
int j = 0;
Employee tmp;
while (swapped) {
swapped = false;
j++;
for (int i = 0; i < a1.length – j; i++) {
if (a1[i].compareTo( a1[i + 1])==1) {
tmp = a1[i];
a1[i] = a1[i + 1];
a1[i + 1] = tmp;
swapped = true;
}
}
}
}
/**
* Bubble Sort will sort by using compare or Comparer and will sort by Last Name
* @param a1 will be the array with all your Employees
*/
public static void bubbleSortbyName(Employee[] a1) {
boolean swapped = true;
int j = 0;
Employee tmp;
while (swapped) {
swapped = false;
j++;
for (int i = 0; i < a1.length – j; i++) {
if (a1[i].compare(a1[i], a1[i + 1])>0) {
tmp = a1[i];
a1[i] = a1[i + 1];
a1[i + 1] = tmp;
swapped = true;
}
}
}
}
}
Employee.java
import java.util.*;
public abstract class Employee implements Cloneable,Comparator<Object>,Comparable<Object>
{
/**
* @lastName last name of Employee
*/
String lastName;
/**
* @firstName first name
*/
String firstName;
/**
* @idNum ID number
*/
String idNum;
/**
* @sex sex(male or female)
*/
String sex;
/**
* @bDay will be object for date of birth of Employees
*/
Calendar bDay = new GregorianCalendar();
//constructor
/**
* this will be your constructor for class
* @param last last name
* @param first first name
* @param id id number
* @param s sex(male or female)
* @param year year born in
* @param month month born in
* @param day day born on
*/
public Employee(String last,String first,String id,String s,int year, int month,int day)
{
lastName=last;
firstName = first;
idNum = id;
sex = s;
bDay.set(Calendar.YEAR,year);
bDay.set(Calendar.MONTH,month);
bDay.set(Calendar.DAY_OF_MONTH,day);
}
//methods
//comparable
/**
* @Override
* This will be your comparable and will no compare by object ID Number
*/
public int compareTo(Object obj)//ID
{
Employee e = (Employee)obj;
int e2 = Integer.parseInt(e.getIDNum());
int e1 = Integer.parseInt(this.idNum);
if(e1<e2)
return 1;
else
return -1;
}
//comparator
/**
* @Override
* This will be your comparator and it will compare by object Last Name
*/
public int compare(Object o1,Object o2)//Last Name
{
Employee e1 =(Employee)o1;
Employee e2 =(Employee)o2;
return e1.lastName.compareTo(e2.lastName);
}
/**
* This will get Last Name of Employee
* @return last name
*/
public String getLastName()
{
return lastName;
}
/** this will get the first name of Employee
*
* @return first name
*/
public String getFirstName()
{
return firstName;
}
/**
* This will get ID number of Employee
* @return ID number
*/
public String getIDNum()
{
return idNum;
}
/**
* This will get the sex of Employee
* @return Male or Female
*/
public String getSex()
{
return sex;
}
/**
* This will get the Birthday of Employee
* @return mm/dd/yyyy
*/
public String getBday()
{
int year=bDay.get(Calendar.YEAR);
int month=bDay.get(Calendar.MONTH);
int day=bDay.get(Calendar.DAY_OF_MONTH);
return String.valueOf(month) + “/” + String.valueOf(day) + “/” + String.valueOf(year);
}
/**
* will change the last name of Employee
* @param change Last name desired
*/
public void setLastName(String change)
{
lastName=change;
}
/**
* will change the first name of Employee
* @param change first name desired
*/
public void setFirstName(String change)
{
firstName=change;
}
/**
* will change the ID number of Employee
*
* @param change ID number desired
*/
public void setID(String change)
{
idNum = change;
}
/**
* will change the sex of Employee
* @param change sex desired(male or female)
*/
public void setSex(String change)
{
sex = change;
}
/**
* will change the Birthday of Employee
* @param month the month desired
* @param day day desired
* @param year year desired
*/
public void setBday(int month,int day,int year)
{
bDay.set(Calendar.MONTH,month);
bDay.set(Calendar.DAY_OF_MONTH,day);
bDay.set(Calendar.YEAR,year);
}
/**
* This will display all important attributes of this class.
*/
public String toString()
{
return “ID Employee number: ” + idNum + “n” + “Employee Name: ” + lastName+” “+firstName + “n” + “Birth Date: ” + bDay.get(Calendar.MONTH)+” / “+bDay.get(Calendar.DAY_OF_MONTH)+” / “+bDay.get(Calendar.YEAR) + “n”;
}
/**
* This is will be your abstract method that will be used in child classes
* @return monthly earning of employee
*/
public abstract double monthlyEarning();
}
Staff.java
import java.util.*;
public class Staff extends Employee
{
/**
* @hourlyRate this will be hourly rate for Employee
*/
int hourlyRate;
/**
* This is your constructor to initialize the following
* @param last last name
* @param first first name
* @param id ID number
* @param s sex(male or female)
* @param year Year born in
* @param month month born in
* @param day day born in
* @param hr hourly rate
*/
public Staff(String last,String first,String id,String s,int year,int month,int day,int hr)
{
super(last,first,id,s,year,month,day );
hourlyRate=hr;
}
/**
* gets the Hourly Rate of Employee
* @return Hourly rate
*/
public int getHourlyRate()
{
return hourlyRate;
}
/**
* Changes the Hourly Rate of Employee
* @param change new Hourly Rate
*/
public void setHourlyRate(int change)
{
hourlyRate=change;
}
/**
* Monthly Earning calculates the Employee’s monthly earning
*/
public double monthlyEarning()
{
double monthlySalary=hourlyRate*EmployeeInfo.staff_monthly_hours_worked;
return monthlySalary;
}
/**
* Displays attributes of class and abstract class Employee
*/
public String toString()
{
return super.toString() + “Full Timen”+”Monthly Salary: ” + monthlyEarning() + “n”;
}
}
Partime.java
public class Partime extends Staff
{
/**
* @hoursWorkedPerWeek this will be the amount of hours the employee works each week
*/
int hoursWorkedPerWeek;
/**
* This will be your constructor for Partime.
* @param last This will be their last name
* @param first This will be their first name
* @param id this will be id number
* @param s sex(male or female)
* @param year year they were born in
* @param month month they were born in
* @param day day they were born in
* @param hourRate how much they earn each hour
* @param hpw how much they worked each week
*/
public Partime(String last,String first,String id,String s,int year,int month,int day,int hourRate,int hpw)
{
super(last, first, id, s,year,month,day, hourRate);
hoursWorkedPerWeek = hpw;
}
/**
* This will give the integer value of how many hours the Employee worked that week
* @return integer value of hours worked that week
*/
public int getHoursWorkedPerWeek()
{
return hoursWorkedPerWeek;
}
/**
* This will change the integer value of hours the employee works in a week
* @param change the new amount of hours per week
*/
public void settHoursWorkedPerWeek(int change)
{
hoursWorkedPerWeek = change;
}
/**
* Monthly Earning will calculate how much the employee earns each month
*/
public double monthlyEarning()
{
return hoursWorkedPerWeek *super.hourlyRate* 4;
}
/**
* Displays last name, first name, ID number, sex(male or female), Birthday, hour per week, and monthly salary for that Employee
*/
public String toString()
{
return super.toString() + “n” + “Hours worked per Week: ” + hoursWorkedPerWeek + “n” + “Monthly Salary: ” + monthlyEarning() + “n”;
}
}
Education.java
public class Education implements Cloneable
{
/**
* @degree This is the degree they received from college
*/
String degree;
/**
* @major This is what they majored in college
*/
String major;
/**
* @research How many research projects they have done
*/
int research;
/**
* constructor for Education initializes degree,major,and research
* @param d Degree
* @param m Major
* @param r Research
*/
public Education(String d, String m, int r)
{
degree = d;
major = m;
research = r;
}
/**
* Gets the Degree the Employee received
* @return Degree(Bachelors,PH.D etc)
*/
public String getDegree()
{
return degree;
}
/**
* Gets Major of Employee
* @return Major(Computer Science,Biology, English, etc)
*/
public String getMajor()
{
return major;
}
/**
* Gets the number of Research Projects the person has done
* @return Number of Research Projects (1,2,3, etc)
*/
public int getReserch()
{
return research;
}
/**
* Changes and Employee’s Degree
* @param change Degree you want to replace the current one with
*/
public void setDegree(String change)
{
degree=change;
}
/**
* Changes the Major of an Employee
* @param change Major you want to replace the current one with
*/
public void setMajor(String change)
{
major = change;
}
/**
* Changes the number of Research Projects
*
* @param change number you want to replace the current one with
*/
public void setResearch(int change)
{
research = change;
}
/**
* clone is here to just clone b. Also if equals doesn’t work then use this one instead of the one in Faculty
*
*/
public Object clone() throws CloneNotSupportedException
{
Education b = (Education) super.clone();
/*
b.setMajor(major);
b.setDegree(degree);
b.setResearch(research);
*/
//if equals doesnt work out comment
return b;
}
/**
* @Override
* Changes the equal fucntion to compare Employee’s degree, major, and research. This to make sure clone() has worked and cloned two objects
* succesfully.
* @param o1 Object to compare with implicit.
*/
public boolean equals(Object o1)
{
Education e = (Education)o1;
if(this.degree.equals(e.degree) && this.major.equals(e.major) && this.research==e.research)
{
return true;
}
else
return false;
}
}
EmployeeInfo.java
public interface EmployeeInfo
{
final double faculty_monthly_salary=6000;
final int staff_monthly_hours_worked=160;
}
Faculty.java
public class Faculty extends Employee
{
/**
* @position This will be the Employee’s position in the company
*/
Level position;
/**
* @e highest education received
*/
Education e;
/**
* @monthlySalary employee’s monthly salary
*/
int monthlySalary;
/**
* Constructor for Faculty will initialize values for class
* @param last last name
* @param first first name
* @param id ID number
* @param s sex(Male or Female)
* @param year year they were born in
* @param month month they were born in
* @param day day they were born
* @param fu position in company
* @param d degree they received from college
* @param m what they majored in
* @param r research projects they have done
*/
public Faculty(String last,String first,String id,String s,int year,int month,int day,Level fu,String d,String m,int r)
{
super(last,first,id,s,year,month,day);
this.position=fu;
e= new Education(d,m,r);
}
//methods
/**
* Finds the how much the employee earns each month. Dependent on position on company as well.
* @return returns Employees Monthly earnings
*/
public double monthlyEarning()
{
switch(position)
{
case AS:
return EmployeeInfo.faculty_monthly_salary;
case AO:
return EmployeeInfo.faculty_monthly_salary*1.5;
case FU:
return EmployeeInfo.faculty_monthly_salary*2.0;
default:
System.out.println(“There’s a PROBLEM OVER HERE!(Facutly Class->monthlyEarning!”);
return 0;
}
}
/**
* Displays everything important for this class in particular. Uses super to display everything important from Employee
* In particulart it displays position,degree,major,and research
*/
public String toString()
{
return super.toString() + “Level: ” + position + “n” + “Degree: ” + e.getDegree() + “n” + “Major: ” + e.getMajor() + “n” + “Research: ” + e.getReserch() + “n” + “Monthly Salary: “+ monthlyEarning() + “n”;
}
/**
* clones objects b and e.
* @return returns object from Faculty
*/
public Object clone() throws CloneNotSupportedException
{
Faculty b = (Faculty) super.clone();
e = (Education) e.clone();
b.setE(e);
return b;
}
/**
* get position of Employee
* @return AS,AO, FU
*/
public Level getPosition() {
return position;
}
/**
* set position changes the position of Employee
* @param Position you want it changed too
*/
public void setPosition(Level position) {
this.position = position;
}
/**
* Gets Education of Employee
* @return Education could be PH.D or Bachelors
*/
public Education getE() {
return e;
}
/**
* Changes Education of Employee
* @param Education you want it changed too
*/
public void setE(Education e) {
this.e = e;
}
/**
* gets the Monthly Salary
* @return Monthly Salary of Employee
*/
public int getMonthlySalary() {
return monthlySalary;
}
/**
* Changes the monthly salary of Employee
* @param monthlySalary salary you want it changed too
*/
public void setMonthlySalary(int monthlySalary) {
this.monthlySalary = monthlySalary;
}
/**
* @Override
* Changes the equals function to compare 2 objects. Tests Clone method to make sure it works
* @return return true or false.
*/
public boolean equals(Object o1)
{
Faculty f = (Faculty)o1;
if(this.e.equals(f.e))
{
return true;
}
else
{
return false;
}
}
}
Level.java
public enum Level
{
AS, //Assistant Professor
AO, //Associate Professor
FU; //Full Time Professor
}
