Suppose that a class, Employee, is defined as follows:
class Employee { String lastName; String firstName; double hourlyWage; int yearsWithCompany; }
Suppose that the data of about 100 employees is already stored in an array:
Employee[] employeeData = new Employee[100];
Thanks for the question.
Below is the code you will be needing Let me know if you have any
doubts or if you need anything to change.
Thank You !!
==============================================================================================
Employee[] employeeData = new Employee[100]; // (a) one that uses a regular for loop for (int i = 0; i < employeeData.length; i++) { if (employeeData[i].getYearsWithCompany() >= 20) { System.out.println("First Name: " + employeeData[i].getFirstName() + ", Last Name: " + employeeData[i].getLastName() + ", Hourly Wage: $" + employeeData[i].getHourlyWage()); } } // (b) one that uses a for-each loop. for (Employee employee : employeeData) { if (employee.getYearsWithCompany() >= 20) { System.out.println("First Name: " + employee.getFirstName() + ", Last Name: " + employee.getLastName() + ", Hourly Wage: $" + employee.getHourlyWage()); } }
Get Answers For Free
Most questions answered within 1 hours.