Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA PLEASE. SUPER SIMPLE!!! Looks like a lot but it is a small task!!! Below is a program that is already completed and runs perfect.

JAVA PLEASE. SUPER SIMPLE!!! Looks like a lot but it is a small task!!! Below is a program that is already completed and runs perfect. The task is to move the employee information from the Test Class to the Employee Class or the Faculty class (which is a subclass of employee). Basically these lines(which are in the Test Class) need to be moved to the Employee or Faculty Class. The Test class will then need to be altererd so that the output remains the same! So in short, Move all lines in BOLD, to the Employee Class or Faculty Class, and rewrite some of the TEST CLASS so that it still outputs the information as it did before.

a1[0] = Factory.getStaff("Allen", "Paita", "123", "M", 1959, 2, 23, 50);

a1[1] = Factory.getStaff("Zapata", "Steven", "456", "F", 1964, 7, 12, 35);

a1[2] = Factory.getStaff("Rios", "Enrique", "789", "M", 1970, 6, 2, 40);

a1[3] = Factory.getFaculty("Johnson", "Anne", "243", "F", 1962, 4, 27, Faculty.Level.FU, "Ph.D", "Engineering", 3);

a1[4] = Factory.getFaculty("Bouris", "William", "791", "F", 1975, 3, 14, Faculty.Level.AO, "Ph.D", "English", 1);

a1[5] = Factory.getFaculty("Andrade", "Christopher", "623", "F", 1980, 5, 2, Faculty.Level.AS, "MS", "Physical Education", 0);

a1[6] = Factory.getPartime("Guzman", "Augusto", "455", "F", 1977, 8, 10, 35, 30);

a1[7] = Factory.getPartime("Depirro", "Martin", "678", "F", 1987, 9, 15, 30, 15);

a1[8] = Factory.getPartime("Aldaco", "Marque", "945", "M", 1988, 24, 11, 20, 35);

PROGRAM:

public interface EmployeeInfo {

final double faculty_monthly_salary = 6000;

final int staff_monthly_hours_worked = 160;

}

import java.util.*;

public abstract class Employee implements Cloneable, Comparator, Comparable

{

/**

*

* @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 birthDay = new GregorianCalendar();

// constructor

/**

*

* constructor for Employee 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;

birthDay.set(Calendar.YEAR, year);

birthDay.set(Calendar.MONTH, month);

birthDay.set(Calendar.DAY_OF_MONTH, day);

}

/**

*

* Compares objects by ID number

*

*/

public int compareTo(Object obj)

{

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

*

* Compares objects by last name

*

* Parameters are the last names

*

*/

public int compare(Object o1, Object o2)

{

Employee e1 = (Employee) o1;

Employee e2 = (Employee) o2;

return e1.lastName.compareTo(e2.lastName);

}

/**

*

* get Last Name of Employee

*

* @return last name

*

*/

public String getLastName()

{

return lastName;

}

/**

* get the first name of Employee

*

* @return first name

*

*/

public String getFirstName()

{

return firstName;

}

/**

*

* get ID number of Employee

*

* @return ID number

*

*/

public String getIDNum()

{

return idNum;

}

/**

*

* get the sex of Employee

*

* @return Male or Female

*

*/

public String getSex()

{

return sex;

}

/**

*

* get the Birthday of Employee using Calendar functions

*

* @return mm/dd/yyyy

*

*/

public String getBday()

{

int year = birthDay.get(Calendar.YEAR);

int month = birthDay.get(Calendar.MONTH);

int day = birthDay.get(Calendar.DAY_OF_MONTH);

return String.valueOf(month) + "/" + String.valueOf(day) + "/" + String.valueOf(year);

}

/**

*

* mutator to change the last name of Employee

*

* @param change

* Last name desired

*

*/

public void setLastName(String change)

{

lastName = change;

}

/**

*

* mutator to change the first name of Employee

*

* @param change

* first name desired

*

*/

public void setFirstName(String change)

{

firstName = change;

}

/**

*

* mutator to change the ID number of Employee

*

* @param change

* ID number desired

*

*/

public void setID(String change)

{

idNum = change;

}

/**

*

* mutator to change the sex of Employee

*

* @param change

* sex desired(male or female)

*

*/

public void setSex(String change)

{

sex = change;

}

/**

*

* mutator to change the Birthday of Employee

*

* @param month

* the month to change to

*

* @param day

* the day to change to

*

* @param year

* the year to change to

*

*/

public void setBday(int month, int day, int year)

{

birthDay.set(Calendar.MONTH, month);

birthDay.set(Calendar.DAY_OF_MONTH, day);

birthDay.set(Calendar.YEAR, year);

}

/**

*

* toString formatted as specified by Assignment

*

*/

public String toString()

{

return "ID Employee number: " + idNum + " " + "Employee Name: " + lastName + " " + firstName + " "

+ "Birth Date: " + birthDay.get(Calendar.MONTH) + " / " + birthDay.get(Calendar.DAY_OF_MONTH) + " / "

+ birthDay.get(Calendar.YEAR) + " " + "Sex: " + sex + " ";

}

/**

*

* abstract method to be used later

*

* @return monthly earning of employee

*

*/

public abstract double monthlyEarning();

}

public class Staff extends Employee

{

/**

*

* @hourlyRate hourly rate for Employee

*

*/

int hourlyRate;

/**

*

* constructor for Staff

*

* @param last

* last name

*

* @param first

* first name

*

* @param id

* ID number

*

* @param s

* sex

*

* @param year

* Birth Year

*

* @param month

* Birth month

*

* @param day

* Birth day

*

* @param hr

* hourly rate

*

*/

public Staff(String last, String first, String id, String s, int year, int month, int day, int hr)

{

// super used to call parent constructor

super(last, first, id, s, year, month, day);

hourlyRate = hr;

}

/**

*

* gets the hourly Rate of Employee

*

* @return hourlyRate

*

*/

public int getHourlyRate()

{

return hourlyRate;

}

/**

*

* Mutator for 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()

{

// staff_monthly_hours_worked from EmployeeInfo

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 Time " + "Monthly Salary: " + monthlyEarning() + " ";

}

}

public class Education implements Cloneable

{

/**

*

* @degree degree they received from college

*

*/

String degree;

/**

*

* @major 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();

return b;

}

/**

*

* Changes the equal function to compare Employee's degree, major, and research.

* Checks if clone() has worked

*

* and cloned two objects successfully and individually.

*

* @param o1

* Object to compare

*

*/

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;

}

}

public class Faculty extends Employee

{

public enum Level

{

AS, // Assistant Professor

AO, // Associate Professor

FU; // Full Time Professor

}

/**

*

* @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

/**

*

* Employee earings based on position

*

* @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;

}

}

/**

*

* toString formatted as specified by the assignment. uses the Super class

*

*/

public String toString()

{

return super.toString() + "Level: " + position + " " + "Degree: " + e.getDegree() + " " + "Major: "

+ e.getMajor() + " " + "Research: " + e.getReserch() + " " + "Monthly Salary: " + monthlyEarning()

+ " ";

}

/**

*

* 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;

}

/**

*

*

*

* 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;

}

}

}

public class Partime extends Staff

{

/**

*

* @hoursWorkedPerWeek this will be the amount of hours the employee works each

* week

*

*/

int hoursWorkedPerWeek;

/**

*

* 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() + " " + "Hours worked per Week: " + hoursWorkedPerWeek + " " + "Monthly Salary: "

+ monthlyEarning() + " ";

}

}

public class Test

{

public static void main(String[] args) throws CloneNotSupportedException

{

//Changed lines below old have been commented

Employee[] a1 = Factory.getEmployees(9);

a1[0] = Factory.getStaff("Allen", "Paita", "123", "M", 1959, 2, 23, 50);

a1[1] = Factory.getStaff("Zapata", "Steven", "456", "F", 1964, 7, 12, 35);

a1[2] = Factory.getStaff("Rios", "Enrique", "789", "M", 1970, 6, 2, 40);

a1[3] = Factory.getFaculty("Johnson", "Anne", "243", "F", 1962, 4, 27, Faculty.Level.FU, "Ph.D", "Engineering", 3);

a1[4] = Factory.getFaculty("Bouris", "William", "791", "F", 1975, 3, 14, Faculty.Level.AO, "Ph.D", "English", 1);

a1[5] = Factory.getFaculty("Andrade", "Christopher", "623", "F", 1980, 5, 2, Faculty.Level.AS, "MS",

"Physical Education", 0);

a1[6] = Factory.getPartime("Guzman", "Augusto", "455", "F", 1977, 8, 10, 35, 30);

a1[7] = Factory.getPartime("Depirro", "Martin", "678", "F", 1987, 9, 15, 30, 15);

a1[8] = Factory.getPartime("Aldaco", "Marque", "945", "M", 1988, 24, 11, 20, 35);

System.out.println("A:");

for (int i = 0; i < 9; i++)

{

System.out.println(a1[i].toString());

}

System.out.println("B: Total Monthly Salary for Partime");

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("C: Total Monthly Salary for All Employees");

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("D: Sorted by ID Number ");

System.out.println(" ");

bubbleSort(a1);

for (int i = 0; i < 9; i++)

{

System.out.println(a1[i].toString());

}

System.out.println("E: Sorted by Last Name ");

bubbleSortbyName(a1);

for (int i = 0; i < 9; i++)

{

System.out.println(a1[i].toString());

}

System.out.println("F: Cloning");

//Changed line below

Faculty abc = Factory.getFaculty("Johnson", "Anne", "243", "F", 1962, 4, 27, Faculty.Level.FU, "Ph.D", "Engineering",

3);

Faculty xyz = (Faculty) abc.clone();

//Changed line below

Education e = Factory.getEducation("MS", "Engineering", 3);

xyz.setE(e);

System.out.println("Clone: " + xyz.toString());

System.out.println("Original: " + abc.toString());

}

/**

*

* 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 by using compare or Comparer and to sort by Last Name

*

* @param a1

* array with all original names

*

*/

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;

}

}

}

}

}

public class Factory {

public static Staff getStaff(String last, String first, String id, String s, int year, int month, int day, int hr) {

return new Staff(last, first, id, s, year, month, day, hr);

}

public static Faculty getFaculty(String last, String first, String id, String s, int year, int month, int day,

Faculty.Level fu, String d, String m, int r) {

return new Faculty(last, first, id, s, year, month, day, fu, d, m, r);

}

public static Partime getPartime(String last, String first, String id, String s, int year, int month, int day,

int hourRate, int hpw) {

return new Partime(last, first, id, s, year, month, day, hourRate, hpw);

}

public static Employee[] getEmployees(int i) {

// TODO Auto-generated method stub

return new Employee[i];

}

public static Education getEducation(String d, String m, int r) {

// TODO Auto-generated method stub

return new Education(d, m, r);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Database And Knowledge Base Systems

Authors: S Krishna

1st Edition

9810206208, 978-9810206208

Students also viewed these Databases questions

Question

WHAT IS AUTOMATION TESTING?

Answered: 1 week ago

Question

What is Selenium? What are the advantages of Selenium?

Answered: 1 week ago