Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

..ooo AT&T; 48%) 11:34 AM gcps.desire2learn.com An employee is eligible for reti

ID: 3602942 • Letter: #

Question

..ooo AT&T; 48%) 11:34 AM gcps.desire2learn.com An employee is eligible for retirement if (s the meets at least two of the following The employes is at least 55 ycars ol 2. The employee has worked for at least 30 years 3. The employee's salary is at least 565,000 A. Given thc following employee's information·dct rmine which employees would be eligible for retirement Name Age Salary Martha The above list of employees, are not sefficient to test a program that would be designod to determine retirement eligibility. Supply additional test data thait would test al B. When writing a program to determine retirement eligibility, how would you handle the eligibility parameters? Would you use a variable, constant or hard code the values for the minimum age, years and salary? Justify your choice. C. Write pseudocode that could be used to determine retirement eligibillny Include declaration and instantiation of any variables or constants dhat you would use to write this piece ed code

Explanation / Answer

/**

* This class represents a employee and all its properties.

*/

public class Employee {

private String name;

private int age;

private int yearsOfEmployement;

private double salary;

private boolean eligible;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public int getYearsOfEmployement() {

return yearsOfEmployement;

}

public void setYearsOfEmployement(int yearsOfEmployement) {

this.yearsOfEmployement = yearsOfEmployement;

}

public double getSalary() {

return salary;

}

public void setSalary(double salary) {

this.salary = salary;

}

public boolean isEligible() {

return eligible;

}

public void setEligible(boolean eligible) {

this.eligible = eligible;

}

@Override

public String toString() {

return "Employee [name=" + name + ", age=" + age + ", yearsOfEmployement=" + yearsOfEmployement + ", salary="

+ salary + ", eligible=" + eligible + "]";

}

}

import java.util.ArrayList;

import java.util.List;

public class EmployeeProcessor {

/**

* These are the constants declared for eligibility criteria. Whenever we are

* using some specific values in computation we should always declare them as

* constants because of re-usability and consistency. Suppose we have used these

* values in multiple places or methods and in future we need to change any of

* these values then we just need to change here at one place only which results

* in consistency.

*

* Variables value can be change at runtime, therefore anyone can change these

* values at any time which might result in wrong result.

*

* These values are stored at global level. So, these values can be used ouside

* of this class also if required.

*/

public static final int RETIRE_MIN_AGE = 55;

public static final int RETIRE_MIN_WORKING_YEARS = 30;

public static final int RETIRE_MIN_SALARY = 65000;

/**

* This is the method used for checking an employee eligibility based on some

* conditions. We can add or remove any condition here if required at any time.

*

* @param employee

* - Employee whose eligibility will be checked.

* @return - true or false.

*/

public static boolean checkEligibility(Employee employee) {

if (employee.getAge() < RETIRE_MIN_AGE) {

return false;

}

if (employee.getSalary() < RETIRE_MIN_SALARY) {

return false;

}

if (employee.getYearsOfEmployement() < RETIRE_MIN_WORKING_YEARS) {

return false;

}

return true;

}

public static void main(String[] args) {

List<Employee> employees = new ArrayList<>();

Employee employee = new Employee();

employee.setName("Martha");

employee.setAge(50);

employee.setYearsOfEmployement(32);

employee.setSalary(55000);

employee.setEligible(checkEligibility(employee));

employees.add(employee);

Employee employee2 = new Employee();

employee2.setName("Ben");

employee2.setAge(55);

employee2.setYearsOfEmployement(30);

employee2.setSalary(70000);

employee2.setEligible(checkEligibility(employee2));

employees.add(employee2);

Employee employee3 = new Employee();

employee3.setName("Tom");

employee3.setAge(60);

employee3.setYearsOfEmployement(28);

employee3.setSalary(60000);

employee3.setEligible(checkEligibility(employee3));

employees.add(employee3);

Employee employee4 = new Employee();

employee4.setName("Betsy");

employee4.setAge(60);

employee4.setYearsOfEmployement(30);

employee4.setSalary(55000);

employee4.setEligible(checkEligibility(employee4));

employees.add(employee4);

for (Employee emp : employees) {

System.out.println(emp);

}

}

}