# Arrays and Iteration - Employee with Second Highest Age Hands-on Solution | TCS Fresco Play | Fresco Play

Disclaimer: The primary purpose of providing this solution is to assist and support anyone who are unable to complete these courses due to a technical issue or a lack of expertise. This website's information or data are solely for the purpose of knowledge and education.

Make an effort to understand these solutions and apply them to your Hands-On difficulties. (It is not advisable that copy and paste these solutions).

All Question of the MCQs Present Below for Ease Use Ctrl + F with the question name to find the Question. All the Best!

If you found answer for any of the questions is wrong. Please do mention in the comment section, could be useful for others. Thanks!

___________________________________________

Arrays and Iteration - Employee with Second Highest Age Hands-on Solution | TCS Fresco Play | Fresco Play

/******Employee.java********************/

import java.util.Comparator;

public class Employee implements Comparable<Employee> {

public int id;

public String name;

public int age;

public Employee(int id, String name, int age) {

this.id = id;

this.name = name;

this.age = age;

}

public int getAge() {

return this.age;

}

@Override

public int compareTo(Employee employee) {

return (this.age - employee.age);

}

}

/******Solution.java****/

import java.util.Arrays;

public class Solution {

public static void main(String[] args) {

Employee e1 = new Employee(1, "aaa", 22);

Employee e2 = new Employee(2, "bbb", 33);

Employee e3 = new Employee(3, "ccc", 55);

Employee e4 = new Employee(4, "ddd", 44);

Employee[] employees = new Employee[]{ e1, e2, e3, e4 };

}

private static Employee employeeWithSecondLowestAge(Employee[] employees) {

Employee[] sortedEmployees = new Employee[employees.length];

Arrays.sort(employees);

return employees[1];

}

}

**************************************************

If you have any queries, please feel free to ask on the comment section.
If you want MCQs and Hands-On solutions for any courses, Please feel free to ask on the comment section too.

Please share and support our page!