Question: public class Employee { private String name; private int age; private int yearsOfService; static int numObj=0; Employee(String name, int newAge, int newYearsOfService) { this.name =

public class Employee {

private String name;

private int age;

private int yearsOfService;

static int numObj=0;

Employee(String name, int newAge, int newYearsOfService)

{

this.name = name;

age = newAge;

yearsOfService = newYearsOfService;

numObj++;

}

Employee()

{

numObj++;

}

void setName(String newName)

{

name = newName;

}

String getName()

{

return name;

}

boolean isEligibleForRetirement()

{

return age+yearsOfService>60;

// if(age+yearsOfService>60)

// return true;

// else

// return false;

}

}

import java.util.Scanner;

public class EmployeeApp {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

String name;

int age;

int yearsOfService;

Employee[] empArray = new Employee[2];

//a loop to take two employees data and create two Employee objects

for(int i=0;i

{

//take user input

System.out.println("Enter an Employee's name");

name = scan.next();

age=20; //scan.nextInt()

yearsOfService=2;

//create an object and keep its reference in the empArray

empArray[i] = new Employee(name, age, yearsOfService);

}

System.out.println("Number of Employee Objects: " + Employee.numObj);

int count=1;

for(Employee e:empArray)

{

System.out.println("Employee" + count +"'s name: " + e.getName());

System.out.println("Emp 1's eligibility for retirement: " + e.isEligibleForRetirement());

count++;

}

}

Use the information above to complete these tasks

Use an Employee array to keep the references to all Employee objects created.

- Ask the user for the number of Employees to be processed. The Employee array needs to accommodate all data. For example, the user may want to create 10 employee's data. Your Employee array should be able to hold 10 Employee object references.

- Use a loop to ask employee data, initialize each element in the Employee array.

- After initializing all elements, print every Employee's information and eligibility for retirement.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!