Question
Java Please comment where each part is in you code. Thanks! Part 1 - Write a method to create a HashMap from a list of
Java
Please comment where each part is in you code. Thanks!
Part 1 -
Write a method to create a HashMap from a list of Employee objects.
The method takes in a list of Employee objects.
The method returns a HashMap that contains those employees hashed by their employee ID.
The Employee class is contained in the downloads for this homework.
The method header is:
public static HashMap
Part 2 -
Write a method to retrieve Employee objects from a HashMap.
The method takes in a HashMap that holds take in a HashMap that holds Employee objects hashed by their employee ID.
The method also takes in a list of Employee IDs.
Some IDs might be in the HashMap, others might not.
Create a list of all Employee objects that match the IDs from the list and are eligible for a bonus.
The Employee class is contained in the downloads for this homework.
The method header is:
public static ArrayList
-----------------------------
Employee.java
public class Employee {
private String firstName, lastName, id;
private boolean bonus; // whether the Employee is eligible for a bonus
public Employee(String firstName, String lastName, String id, boolean bonus) {
this.firstName = firstName;
this.lastName = lastName;
this.id = id;
this.bonus = bonus;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public boolean isBonus() {
return bonus;
}
public void setBonus(boolean bonus) {
this.bonus = bonus;
}
@Override
public String toString() {
return "Employee: " + lastName + ", " + firstName + " (ID: " + id + ")" +
(bonus ? " (Eligible for Bonus)" : "");
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started