I'm looking for a review on the following classes and the comments I applied (class assignment):
package assignment1;
/**
* Returns a GeneralEmployee object
* Sets the name, id for the object when called.
* It increments the id that is assigned to a new employee object so that each employee gets a unique id
* It can be used to compare if another GeneralEmployee object is equal
* @author me
*
*/
public abstract class GeneralEmployee implements Employee {
private String name;
private static int initialId = 0;
private int id;
/**
* Sets name to passed name param
* Increments initialID by 1
* sets id to value of intialId
* @param name
*/
public GeneralEmployee(String name) {
super();
this.setName(name);
initialId++;
id = Integer.valueOf(initialId);
}
/**
* Returns the name of the emloyee
* @return
*/
public String getName() {
return name;
}
/**
* Sets the name of the employee
* @param name
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns the id of the employee
* @return
*/
public int getId() {
return id;
}
/*
* Returns a String comprising the name, id and pay of the employee
*/
public String toString() {
return "name " + getName() + " id " + getId() + " pay " + getPayCheckAmount();
}
/*
* Returns true if the GeneralEmployee object passed to it is equal to the current GeneralEmployee object
*/
public boolean equals(Object anOject){
GeneralEmployee generalEmployee;
try {
generalEmployee = (GeneralEmployee) anOject;
} catch (Exception e) {
return false;
}
return generalEmployee.id==id;
}
}
package assignment1;
/**
* This class extends GeneralEmployee
* It is used to set and get the hoursWorked and calculate payCheckAmount based on hoursWorked
* @author me
*
*/
public class PartTimeEmployee extends GeneralEmployee{
private double hoursWorked;
private double hourlyPayRate;
/**
* Set name and hourly rate of employee
* @param name
* @param hourlyPayRate
*/
public PartTimeEmployee(String name, double hourlyPayRate) {
super(name);
this.hourlyPayRate = hourlyPayRate;
}
/*
* Return payCheckAmount by checking if hoursWorked > 40
* If hoursWorked greater then 40 then calculate regular pay plus overtime pay
* If hoursWorked is not greater then just calculate regular pay *
* @return payCheckAmount
*/
@Override
public double getPayCheckAmount() {
double payCheckAmount;
if(hoursWorked > 40){
payCheckAmount = (40 * hourlyPayRate) + ((hoursWorked - 40) * (1.5 * hourlyPayRate));
}
else{
payCheckAmount = hoursWorked * hourlyPayRate;
}
return payCheckAmount;
}
/**
* Return hoursWorked
* @return hoursWorked
*/
public double getHoursWorked() {
return hoursWorked;
}
/**
* Set hoursWorked
* @param hoursWorked
*/
public void setHoursWorked(double hoursWorked){
this.hoursWorked = this.hoursWorked + hoursWorked;
}
}
package assignment1;
/**
* Runnable class that will create 5 employees, setting their name, hourlyPayRate and hoursWorked and to return the payCheckAmount based
* on those set values
*
* Also checks to see if any employees have a duplicate id
*
* @author me
*
*/
public class Driver {
/**
* Used to start program
* @param args
*/
public static void main(String args[]){
PartTimeEmployee employee1, employee2,employee3,employee4,employee5;
// working over 40 hours
employee1 = new PartTimeEmployee("bob", 5);
employee1.setHoursWorked(8);
employee1.setHoursWorked(8);
employee1.setHoursWorked(8);
employee1.setHoursWorked(8);
employee1.setHoursWorked(10);
System.out.println(employee1.toString());
// working under 40 hours
employee2 = new PartTimeEmployee("cindy", 5.5);
employee2.setHoursWorked(0);
employee2.setHoursWorked(0);
employee2.setHoursWorked(10);
employee2.setHoursWorked(10);
employee2.setHoursWorked(0);
System.out.println(employee2.toString());
// working 40 hours
employee3 = new PartTimeEmployee("fred", 6);
employee3.setHoursWorked(8);
employee3.setHoursWorked(8);
employee3.setHoursWorked(8);
employee3.setHoursWorked(8);
employee3.setHoursWorked(8);
System.out.println(employee3.toString());
// working over 4 hours
employee4 = new PartTimeEmployee("jim", 6.5);
employee4.setHoursWorked(8);
employee4.setHoursWorked(8);
employee4.setHoursWorked(8);
employee4.setHoursWorked(10);
employee4.setHoursWorked(10);
System.out.println(employee4.toString());
// working 0 hours
employee5 = new PartTimeEmployee("lucy", 7);
employee5.setHoursWorked(0);
employee5.setHoursWorked(0);
employee5.setHoursWorked(0);
employee5.setHoursWorked(0);
employee5.setHoursWorked(0);
System.out.println(employee5.toString());
Employee employees[] = new Employee[]{employee1,employee2,employee3,employee4,employee5};
// call method to check if any of the created employees have a duplicate id
checkIfEmployeeIdIsDuplicate(employees);
}
/**
* @param employees
* @return true if a duplicate id is found for PartTimeEmployee
*/
private static boolean checkIfEmployeeIdIsDuplicate(Employee employees[]){
if(employees!=null){
for (int i = 0; i < employees.length; i++) {
for (int j = 0; j < employees.length; j++) {
Object object1 = employees[i];
Object object2 = employees[j];
if (object1 != null && object2 != null && i!=j) {
PartTimeEmployee DuplicateEmployeeId1 = (PartTimeEmployee)object1;
PartTimeEmployee DuplicateEmployeeId2 = (PartTimeEmployee)object2;
if (DuplicateEmployeeId1.equals(DuplicateEmployeeId2)) {
System.out.println(DuplicateEmployeeId1.toString() + " equals name " + DuplicateEmployeeId2.toString());
}
}
}
}
}
return false;
}
}
package assignment1;
/**
* interface used for making sure there is a method to return the payCheckAmount
* @author me
*
*/
public interface Employee {
public double getPayCheckAmount();
}