/**
* This class contains methods to process arrays of {@link Employee} objects.
*
* @author Michael
* @version 1.0.0
* @see Employee
*/
public class EmployeeArray {
/**
* Creates an array with three objects of class {@link Employee}.
* <p>
* The first element of the array is the object <code>first</code>, the
* second element of the array is the object <code>second</code>, and the
* third element of the array is the object <code>third</code>.
* </p>
*
* @param first
* a {@link Employee} object.
* @param second
* a {@link Employee} object.
* @param third
* a {@link Employee} object.
* @return an array with the objects <code>first</code>,
* <code>second</code>, and <code>third</code>.
*/
public static Employee[] makeArray(Employee first, Employee second,
Employee third) {
/* PLACE YOUR CODE HERE */
Employee[] employees = new Employee[3];
employees[0] = first;
employees[1] = second;
employees[2] = third;
return employees; // REMOVE; USED SO THIS FILE COMPILES
}
/**
* Creates a new array from the specified array of {@link Employee} objects.
* <p>
* The elements in the new array have the same order as those in the
* specified array.
* </p>
*
* @param array
* an array that contains objects of class {@link Employee}.
* @return a <i>new</i> array of the objects in the specified array.
*/
public static Employee[] copyArray(Employee[] array) {
/* PLACE YOUR CODE HERE */
Employee[] newArray = new Employee[array.length];
for (int i = 0; i < array.length; i++) {
newArray[i] = array[i];
}
return newArray; // REMOVE; USED SO THIS FILE COMPILES
}
/**
* Returns the {@link Employee} object with the specified ID.
*
* @param array
* an array that contains objects of class {@link Employee}.
* @param id
* an employee ID.
* @return The {@link Employee} object with the specifed ID. Returns
* <code>null</code> if there are no employees in the specified
* array with the specifed ID.
*/
public static Employee getEmployee(Employee[] array, int id) {
for (int i = 0; i < array.length; i++) {
if (array[i].getId() == id) {
return array[i];
}
}
return null;
}
/**
* Returns the number of employees whose salary is higher than the specified
* dollar amount.
*
* @param array
* an array that contains objects of class {@link Employee}.
* @param amount
* a dollar amount.
* @return the number of employees whose salary is higher than the specified
* dollar amount.
*/
public static int countHigherSalaries(Employee[] array, double amount) {
/* PLACE YOUR CODE HERE */
int i = 0, n = 0;
for (i = 0; i < array.length; i++) {
if (array[i].getSalary() > amount) {
n++;
}
}
return n; // REMOVE; USED SO THIS FILE COMPILES
}
/**
* Returns the sum of the salaries of the employees in the specified array.
*
* @param array
* an array that contains objects of class {@link Employee}.
* @return the sum of the salaries of the employees in the specified array.
*/
public static double sumSalaries(Employee[] array) {
/* PLACE YOUR CODE HERE */
double sumSalary = 0.0;
for (int i = 0; i < array.length; i++) {
sumSalary += array[i].getSalary();
}
return sumSalary; // REMOVE; USED SO THIS FILE COMPILES
}
/**
* Obtains the highest salary in the specified array.
*
* @param array
* an array that contains objects of class {@link Employee}.
* @return the highest salary in the specified array.
*/
public static double getHighestSalary(Employee[] array) {
/* PLACE YOUR CODE HERE */
double highestSalary = 0.0;
for (int i = 0; i < array.length; i++) {
if (array[i].getSalary() > highestSalary) {
highestSalary = array[i].getSalary();
}
}
return highestSalary; // REMOVE; USED SO THIS FILE COMPILES
}
/**
* Increases the salary of every employee in the specified array by the
* specified amount.
*
* @param array
* an array that contains objects of class {@link Employee}.
*/
public static void increaseAll(Employee[] array, double amount) {
/* PLACE YOUR CODE HERE */
for (int i = 0; i < array.length; i++) {
array[i].setSalary(amount + array[i].getSalary());
}
}
public static String displayAll(Employee[] array) {
/* PLACE YOUR CODE HERE */
String allEmployee = "";
if (array == null) {
return null;
} else {
for (int i = 0; i < array.length; i++) {
allEmployee = array[0].toString() + "\n" + array[1].toString()
+ "\n" + array[2].toString() + "\n"
+ array[3].toString();
}
}
return allEmployee; // REMOVE; USED SO THIS FILE COMPILES
}
}