0

I realize that variations of this question have been asked before, but I am having a uniquely difficult time figuring out how to complete the following task:

I have an object that looks something like this (please note, "Skill" and "Certification" are ENUMS):

Public Employee {

String name;
List<Skill> employableSkills = new ArrayList<>();
List<Certification> certifications = new ArrayList<>(); 
   ...
}

In another class, I've got a

List<Employee> listOfEmployees;

and I'm trying to loop through it like this:

// determine the total number of employees who know Java

int numberOfEmployeesWhoKnowJava = 0;

for (Employee employee : listOfEmployees) {
    if (employee.employableSkills.contains( ?? )) {

numberOfEmployeesWhoKnowJava++;
}

I'm struggling to get the exact syntax on the if-statement. I have tried this:

if(employee.employableSkills.contains(Employee.EmployableSkills.JAVA)) {

but EmployableSkills in this string gets "cannot resolve symbol."

How should I loop through the List on each Employee object and check if it contains JAVA?

Edit: It turns out I was making a fundamental error. In OOP, it is best not to expose the data from one class to another class. Instead, I wrote getters in the Employee class, then called those getters from my other class. That way, the data in Employee is not directly exposed to the class that needed it.

1
  • Can you share the definition of that enum Skill? Commented Sep 25, 2019 at 20:25

2 Answers 2

2

Even if you get syntax right, the following code will have a bad complexity of order n - O(n).

if(employee.employableSkills.contains(Employee.EmployableSkills.JAVA)) {

Change you List to hash implementation of set

Set<Skill> employableSkills = new HashSet<>();

and now loop through the employees

int numberOfEmployeesWhoKnowJava = 0;
for (Employee employee : listOfEmployees) {
  if (employee.employableSkills.contains(Skill.JAVA)) {
     numberOfEmployeesWhoKnowJava++;
  } 
}

This will give a complexity of O(1) while looking skills

Sign up to request clarification or add additional context in comments.

Comments

0

Your question is a little unclear, but if my interpretation is correct, try this:

if (employee.employableSkills.contains(Skill.JAVA))

3 Comments

This gives me the same issue: "Cannot resolve symbol: Skill"
@Umbrella_Programmer Import it.
Like I said your question is a little unclear, @Umbrella_Programmer, please post EVERYTHING

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.