using java(Factory method ) : I want the user to input the employee information
ID: 3598522 • Letter: U
Question
using java(Factory method ) :
I want the user to input the employee information depending in their postion and then
display the following outputs:
a. Employee information :
Staff
Faculty
Part-time
b. Total monthly salary for all the part-time staff .
c. Total monthly salary for all employees.
d. Display all employee information descending by employee id using interface Comparable
e. Display all employee information ascending by last name using interface Comparer
f. Duplicate a faculty object using clone. Verify the duplication.
the postions ::
Staff :
Last name
First name
ID
Sex
Birth date
Hourly rate
Faculty:
Last name
First name
ID
Sex
Birth date
Hourly rate
Level:
Degree
Major:
Reseach:
3- Part-time
Last name
First name
ID
Sex
Birth date
Hourly rate
Hours worked per week
the code :
this is the main class for factoy pattren for employee
Class EmployeeClicnt
public class EmployeeClicnt {
public static void main(String[] args) {
EmployeeFactory factory = new EmployeeFactory();
Employee e[] = new Employee [5];
e[0]= factory.createEmployee(EmployeeFactory.Type.FACULTY);
e[0].inputEmployee();
e[1]= factory.createEmployee(EmployeeFactory.Type.FACULTY);
e[1].inputEmployee();
e[3]= factory.createEmployee(EmployeeFactory.Type.STAFF);
e[3].inputEmployee();
e[4]= factory.createEmployee(EmployeeFactory.Type.STAFF);
e[4].inputEmployee();
e[5]= factory.createEmployee(EmployeeFactory.Type.PARTTIME);
e[5].inputEmployee();
e[6]= factory.createEmployee(EmployeeFactory.Type.PARTTIME);
e[6].inputEmployee();
for (int j =0; j<e.length;j++)
{
e[j].toString();
}
String typeF= e[0].getClass().getName();
for(int i=0; i<e.length;i++)
if(typeF.equals(e[i].getClass().getName()))
{
e[i].monthlyEarning(); }
}
}
EmployeeFactory :
public class EmployeeFactory {
public enum Type{FACULTY,STAFF,PARTTIME}
private Employee e;;
public Employee createEmployee(Type type)
{
switch(type)
{
case FACULTY :
e = new Faculty(null, null, null, null, 1, 1, 1, null, "test", "test", 0);
case STAFF :
e = new Staff(null, null, null, null, 0, 0, 0, 0);
case PARTTIME :
e = new Partime(null, null, null, null, 0, 0, 0, 0, 0);
}
return e ;
}
}
Staff :
public class Staff extends Employee
{
int hourlyRate;
/**
* This is the constructor t
* @param last last name
* @param first first name
* @param id ID number
* @param s (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;
}
/**
* this is a getter method for hourly Rate
*/
public int getHourlyRate()
{
return hourlyRate;
}
/**
* this is a setter method for hourly Rate
* @param set the new Hourly Rate
*/
public void setHourlyRate(int change)
{
hourlyRate=change;
}
/**
* this is method calculate the monthly rate
*/
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 Time "+"Monthly Salary: " + monthlyEarning() + " ";
}
public void inputEmployee() {
super.inputEmployee();
System.out.println("Enter the hourly rate:");
Scanner scanner = new Scanner(System.in);
hourlyRate = scanner.nextInt();
}
}
Partime :
public class Partime extends Staff
{
int hoursWorkedPerWeek;
/**
* This is the constructor.
* @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 (male or female)
* @param year the year of birth
* @param month the month of birth
* @param day the day of the birth
* @param hour Rate how much they get each hour
* @param hpw how many hours per week they work
*/
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 a getter method for Hours Worked Per Week
*/
public int getHoursWorkedPerWeek()
{
return hoursWorkedPerWeek;
}
/**
* This a setter method for Hours Worked Per Week
* @param set the Hours Worked Per Week
*/
public void settHoursWorkedPerWeek(int change)
{
hoursWorkedPerWeek = change;
}
/**
* calculate how much the employee get paid 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 void inputEmployee() {
super.inputEmployee();
System.out.println("Enter hours Worked Per Week:");
Scanner scanner = new Scanner(System.in);
hoursWorkedPerWeek = scanner.nextInt();
}
}
Faculty
public class Faculty extends Employee
{
Level position; // Employee's Position
String postionChoice;
Education e; // the highest education level received
Level AS;
int monthlySalary;// the monthly salary
private Level AO;
private Level FU;
private String d;
private String m;
private int r;
/**
* This is the Constructor
* @param last last name
* @param first first name
* @param id ID number
* @param s (Male or Female)
* @param year the year of the birth
* @param month the month of the birth
* @param day the day of the birth
* @param pos 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 pos,String d,String m,int r)
{
super(last,first,id,s,year,month,day);
this.position=pos;
e= new Education(d,m,r);
}
/**
* this method calculate how much employees make per month depending on their position.
* @return returns Employees Monthly Salary
*/
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 + " " + "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;
}
/**
* This is a getter for position
* @return the postion
*/
public Level getPosition() {
return position;
}
/**
* this is a setter method for position
* @param Position that to set
*/
public void setPosition(Level position) {
this.position = position;
}
/**
* this a getter method for Education
* @return Education
*/
public Education getE() {
return e;
}
/**
* this is a setter method for Education
* @param Education that to set
*/
public void setE(Education e) {
this.e = e;
}
/**
* this is a getter method for Monthly salary
* @return Monthly Salary
*/
public int getMonthlySalary() {
return monthlySalary;
}
/**
* this is a setter method for monthly salary
* @param monthlySalary salary to change
*/
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;
}
}
public void inputEmployee() {
super.inputEmployee();
System.out.println("Enter the postion:");
Scanner scanner = new Scanner(System.in);
postionChoice = scanner.nextLine();
if(postionChoice == "AS")
{
position = Level.AS;
setPosition(position);
}
if(postionChoice == "AO")
{
position = Level.AO;
setPosition(position);
}
if(postionChoice == "FU")
{
position = Level.FU;
setPosition(position);
}
System.out.println("Enter the degree they received from college:");
d = scanner.nextLine();
System.out.println("Enter the major they received from college:");
m = scanner.nextLine();
System.out.println("Enter the research projects they have done");
r = scanner.nextInt();
e = new Education(d,m,r);
}
}
Employee :
public abstract class Employee implements Cloneable,Comparator,Comparable
{
//Attributes:
String lastName;
String firstName;
String idNum;//Id number
String sex; //(Male or Female)
Calendar bDay = new GregorianCalendar(); //using the Calendar Java class to create a date object
private int year;
private int month;
private int day;
/**
* This the constructor
* @param last the last name
* @param first the first name
* @param id the id number
* @param se Male of Female
* @param year the year of the birth
* @param month the month of the birth
* @param day the day of birth
*/
public Employee(String last,String first,String id,String se,int year, int month,int day)
{
lastName=last;
firstName = first;
idNum = id;
sex = se;
bDay.set(Calendar.YEAR,year);
bDay.set(Calendar.MONTH,month);
bDay.set(Calendar.DAY_OF_MONTH,day);
}
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;
}
public int compare(Object o1,Object o2)
{
Employee e1 =(Employee)o1;
Employee e2 =(Employee)o2;
return e1.lastName.compareTo(e2.lastName);
}
/**
* this is a getter method for Last name
* @return last name
*/
public String getLastName()
{
return lastName;
}
/**
* this is a getter method for First name
* @return First name
*/
public String getFirstName()
{
return firstName;
}
/**
* this is a getter method for Id number
* @return Id number
*/
public String getIDNum()
{
return idNum;
}
/**
* this is a getter method for sex
* @return sex
*/
public String getSex()
{
return sex;
}
/**
* this is a getter method for birthday date
* @return the birthday date as month/day/year
*/
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);
}
/**
* this is setter method for Last name
* @param change last name
*/
public void setLastName(String change)
{
lastName=change;
}
/**
* this is setter method for First name
* @param change
*/
public void setFirstName(String change)
{
firstName=change;
}
/**
* this is setter method for Id number
* @param change Id number
*/
public void setID(String change)
{
idNum = change;
}
/**
* this is setter method for sex
* @param change sex
*/
public void setSex(String change)
{
sex = change;
}
/**
* this is setter method for Birth day
* @param month set the month
* @param day set the day
* @param year set the year
*/
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);
}
/**
*
* returning a string with the following format:
* ID Employee number
* Employee name
* Birth date
*/
public String toString()
{
return "ID Employee number: " + idNum + " " + "Employee Name: " + lastName+" "+firstName + " " + "Birth Date: " + bDay.get(Calendar.MONTH)+" / "+bDay.get(Calendar.DAY_OF_MONTH)+" / "+bDay.get(Calendar.YEAR) + " ";
}
/**
* This the abstract method of monthlyEarning
* @return monthlyEarning
*/
public void inputEmployee() {
System.out.println("Enter the last name:");
Scanner scanner = new Scanner(System.in);
lastName = scanner.nextLine();
System.out.println("Enter the First name:");
firstName = scanner.nextLine();
System.out.println("Enter the ID number:");
idNum = scanner.nextLine();
System.out.println("Enter type of sex:");
sex = scanner.nextLine();
System.out.println("Enter year of birth:");
year = scanner.nextInt();
System.out.println("Enter month of birth:");
month = scanner.nextInt();
System.out.println("Enter day of birth:");
day = scanner.nextInt();
bDay.set(Calendar.YEAR,year);
bDay.set(Calendar.MONTH,month);
bDay.set(Calendar.DAY_OF_MONTH,day);
}
public abstract double monthlyEarning();
}
interface EmployeeInfo:
public interface EmployeeInfo
{
final double faculty_monthly_salary=6000;
final int staff_monthly_hours_worked=160;
}
Level:
public enum Level
{
AS, //Assistant Professor
AO, //Associate Professor
FU; //Full Time Professor
}
Eduction:
public class Education implements Cloneable
{
String degree;
String major;
int research;
/**
* This is the constructor
* @param d Degree
* @param m Major
* @param r Research
*/
public Education(String d, String m, int r)
{
degree = d;
major = m;
research = r;
}
/**
* this is a getter method of degree
* @return the degree
*/
public String getDegree()
{
return degree;
}
/**
* This is a getter method of Major
* @return the major
*/
public String getMajor()
{
return major;
}
/**
* this is a getter method of research
* @return number of research
*/
public int getReserch()
{
return research;
}
/**
* this is a setter method of degree
* @param set the new degree
*/
public void setDegree(String change)
{
degree=change;
}
/**
* This is a getter method of Major
* @param set the new major
*/
public void setMajor(String change)
{
major = change;
}
/**
* this is a setter method of research
*
* @param set the new research amount
*/
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;
}
}
Explanation / Answer
Class EmployeeClicnt
public class EmployeeClicnt {
public static void main(String[] args) {
EmployeeFactory factory = new EmployeeFactory();
Employee e[] = new Employee [5];
e[0]= factory.createEmployee(EmployeeFactory.Type.FACULTY);
e[0].inputEmployee();
e[1]= factory.createEmployee(EmployeeFactory.Type.FACULTY);
e[1].inputEmployee();
e[3]= factory.createEmployee(EmployeeFactory.Type.STAFF);
e[3].inputEmployee();
e[4]= factory.createEmployee(EmployeeFactory.Type.STAFF);
e[4].inputEmployee();
e[5]= factory.createEmployee(EmployeeFactory.Type.PARTTIME);
e[5].inputEmployee();
e[6]= factory.createEmployee(EmployeeFactory.Type.PARTTIME);
e[6].inputEmployee();
for (int j =0; j<e.length;j++)
{
e[j].toString();
}
String typeF= e[0].getClass().getName();
for(int i=0; i<e.length;i++)
if(typeF.equals(e[i].getClass().getName()))
{
e[i].monthlyEarning(); }
}
}
EmployeeFactory :
public class EmployeeFactory {
public enum Type{FACULTY,STAFF,PARTTIME}
private Employee e;;
public Employee createEmployee(Type type)
{
switch(type)
{
case FACULTY :
e = new Faculty(null, null, null, null, 1, 1, 1, null, "test", "test", 0);
case STAFF :
e = new Staff(null, null, null, null, 0, 0, 0, 0);
case PARTTIME :
e = new Partime(null, null, null, null, 0, 0, 0, 0, 0);
}
return e ;
}
}
Staff :
public class Staff extends Employee
{
int hourlyRate;
/**
* This is the constructor t
* @param last last name
* @param first first name
* @param id ID number
* @param s (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;
}
/**
* this is a getter method for hourly Rate
*/
public int getHourlyRate()
{
return hourlyRate;
}
/**
* this is a setter method for hourly Rate
* @param set the new Hourly Rate
*/
public void setHourlyRate(int change)
{
hourlyRate=change;
}
/**
* this is method calculate the monthly rate
*/
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 Time "+"Monthly Salary: " + monthlyEarning() + " ";
}
public void inputEmployee() {
super.inputEmployee();
System.out.println("Enter the hourly rate:");
Scanner scanner = new Scanner(System.in);
hourlyRate = scanner.nextInt();
}
}
Partime :
public class Partime extends Staff
{
int hoursWorkedPerWeek;
/**
* This is the constructor.
* @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 (male or female)
* @param year the year of birth
* @param month the month of birth
* @param day the day of the birth
* @param hour Rate how much they get each hour
* @param hpw how many hours per week they work
*/
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 a getter method for Hours Worked Per Week
*/
public int getHoursWorkedPerWeek()
{
return hoursWorkedPerWeek;
}
/**
* This a setter method for Hours Worked Per Week
* @param set the Hours Worked Per Week
*/
public void settHoursWorkedPerWeek(int change)
{
hoursWorkedPerWeek = change;
}
/**
* calculate how much the employee get paid 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 void inputEmployee() {
super.inputEmployee();
System.out.println("Enter hours Worked Per Week:");
Scanner scanner = new Scanner(System.in);
hoursWorkedPerWeek = scanner.nextInt();
}
}
Faculty
public class Faculty extends Employee
{
Level position; // Employee's Position
String postionChoice;
Education e; // the highest education level received
Level AS;
int monthlySalary;// the monthly salary
private Level AO;
private Level FU;
private String d;
private String m;
private int r;
/**
* This is the Constructor
* @param last last name
* @param first first name
* @param id ID number
* @param s (Male or Female)
* @param year the year of the birth
* @param month the month of the birth
* @param day the day of the birth
* @param pos 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 pos,String d,String m,int r)
{
super(last,first,id,s,year,month,day);
this.position=pos;
e= new Education(d,m,r);
}
/**
* this method calculate how much employees make per month depending on their position.
* @return returns Employees Monthly Salary
*/
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 + " " + "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;
}
/**
* This is a getter for position
* @return the postion
*/
public Level getPosition() {
return position;
}
/**
* this is a setter method for position
* @param Position that to set
*/
public void setPosition(Level position) {
this.position = position;
}
/**
* this a getter method for Education
* @return Education
*/
public Education getE() {
return e;
}
/**
* this is a setter method for Education
* @param Education that to set
*/
public void setE(Education e) {
this.e = e;
}
/**
* this is a getter method for Monthly salary
* @return Monthly Salary
*/
public int getMonthlySalary() {
return monthlySalary;
}
/**
* this is a setter method for monthly salary
* @param monthlySalary salary to change
*/
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;
}
}
public void inputEmployee() {
super.inputEmployee();
System.out.println("Enter the postion:");
Scanner scanner = new Scanner(System.in);
postionChoice = scanner.nextLine();
if(postionChoice == "AS")
{
position = Level.AS;
setPosition(position);
}
if(postionChoice == "AO")
{
position = Level.AO;
setPosition(position);
}
if(postionChoice == "FU")
{
position = Level.FU;
setPosition(position);
}
System.out.println("Enter the degree they received from college:");
d = scanner.nextLine();
System.out.println("Enter the major they received from college:");
m = scanner.nextLine();
System.out.println("Enter the research projects they have done");
r = scanner.nextInt();
e = new Education(d,m,r);
}
}
Employee :
public abstract class Employee implements Cloneable,Comparator,Comparable
{
//Attributes:
String lastName;
String firstName;
String idNum;//Id number
String sex; //(Male or Female)
Calendar bDay = new GregorianCalendar(); //using the Calendar Java class to create a date object
private int year;
private int month;
private int day;
/**
* This the constructor
* @param last the last name
* @param first the first name
* @param id the id number
* @param se Male of Female
* @param year the year of the birth
* @param month the month of the birth
* @param day the day of birth
*/
public Employee(String last,String first,String id,String se,int year, int month,int day)
{
lastName=last;
firstName = first;
idNum = id;
sex = se;
bDay.set(Calendar.YEAR,year);
bDay.set(Calendar.MONTH,month);
bDay.set(Calendar.DAY_OF_MONTH,day);
}
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;
}
public int compare(Object o1,Object o2)
{
Employee e1 =(Employee)o1;
Employee e2 =(Employee)o2;
return e1.lastName.compareTo(e2.lastName);
}
/**
* this is a getter method for Last name
* @return last name
*/
public String getLastName()
{
return lastName;
}
/**
* this is a getter method for First name
* @return First name
*/
public String getFirstName()
{
return firstName;
}
/**
* this is a getter method for Id number
* @return Id number
*/
public String getIDNum()
{
return idNum;
}
/**
* this is a getter method for sex
* @return sex
*/
public String getSex()
{
return sex;
}
/**
* this is a getter method for birthday date
* @return the birthday date as month/day/year
*/
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);
}
/**
* this is setter method for Last name
* @param change last name
*/
public void setLastName(String change)
{
lastName=change;
}
/**
* this is setter method for First name
* @param change
*/
public void setFirstName(String change)
{
firstName=change;
}
/**
* this is setter method for Id number
* @param change Id number
*/
public void setID(String change)
{
idNum = change;
}
/**
* this is setter method for sex
* @param change sex
*/
public void setSex(String change)
{
sex = change;
}
/**
* this is setter method for Birth day
* @param month set the month
* @param day set the day
* @param year set the year
*/
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);
}
/**
*
* returning a string with the following format:
* ID Employee number
* Employee name
* Birth date
*/
public String toString()
{
return "ID Employee number: " + idNum + " " + "Employee Name: " + lastName+" "+firstName + " " + "Birth Date: " + bDay.get(Calendar.MONTH)+" / "+bDay.get(Calendar.DAY_OF_MONTH)+" / "+bDay.get(Calendar.YEAR) + " ";
}
/**
* This the abstract method of monthlyEarning
* @return monthlyEarning
*/
public void inputEmployee() {
System.out.println("Enter the last name:");
Scanner scanner = new Scanner(System.in);
lastName = scanner.nextLine();
System.out.println("Enter the First name:");
firstName = scanner.nextLine();
System.out.println("Enter the ID number:");
idNum = scanner.nextLine();
System.out.println("Enter type of sex:");
sex = scanner.nextLine();
System.out.println("Enter year of birth:");
year = scanner.nextInt();
System.out.println("Enter month of birth:");
month = scanner.nextInt();
System.out.println("Enter day of birth:");
day = scanner.nextInt();
bDay.set(Calendar.YEAR,year);
bDay.set(Calendar.MONTH,month);
bDay.set(Calendar.DAY_OF_MONTH,day);
}
public abstract double monthlyEarning();
}
interface EmployeeInfo:
public interface EmployeeInfo
{
final double faculty_monthly_salary=6000;
final int staff_monthly_hours_worked=160;
}
Level:
public enum Level
{
AS, //Assistant Professor
AO, //Associate Professor
FU; //Full Time Professor
}
Eduction:
public class Education implements Cloneable
{
String degree;
String major;
int research;
/**
* This is the constructor
* @param d Degree
* @param m Major
* @param r Research
*/
public Education(String d, String m, int r)
{
degree = d;
major = m;
research = r;
}
/**
* this is a getter method of degree
* @return the degree
*/
public String getDegree()
{
return degree;
}
/**
* This is a getter method of Major
* @return the major
*/
public String getMajor()
{
return major;
}
/**
* this is a getter method of research
* @return number of research
*/
public int getReserch()
{
return research;
}
/**
* this is a setter method of degree
* @param set the new degree
*/
public void setDegree(String change)
{
degree=change;
}
/**
* This is a getter method of Major
* @param set the new major
*/
public void setMajor(String change)
{
major = change;
}
/**
* this is a setter method of research
*
* @param set the new research amount
*/
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;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.