Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider a Worker class defined as follows: (assume that all get/set methods are

ID: 3801520 • Letter: C

Question

Consider a Worker class defined as follows: (assume that all get/set methods are available). public class Worker {private string name; private int income; Now assume that you have a Store class that maintains a HashMap of Worker objects in an attribute called workers. The keys for the HashMap are the individual departments that workers work in (e.g., "Clothing", "Housewares"). The values of the HashMap are ArrayLists of Worker objects that work in that department. Complete the following two instance methods for the Store class using proper code. Write a departmentFor() method that returns the department that the given worker is in (null should be the proper answer if the worker does not work at that store): public String departmentFor (Worker w) {Set departments = b) Complete the add() method that adds a new worker to the specified department in the store by updating the workers attribute accordingly: public void add(Worker newGuy, String department){

Explanation / Answer

Answer:

a. Below is the required method:

public String departmentFor(Worker w){
   Set<String> departments = w.department;
   return departments;
   /*As per the Worker class, the details of the worker comes with the data provided. So when one wants set the departments which workers work for can be obtained from the worker details.*/
}

b. Below is the required method:

public void add(Worker newGuy, String department){
   /*In order to add a newGuy, assign all the values rewuired*/
   System.out.println("Enter the name of the new guy::");
   newGuy.name = scanner.nextLine();
   System.out.println("Enter the income of the new guy::");
   newGUy.income = scanner.nextInt();
       .
       .
       .
   /*Similarly, ask the user to enter the required values*/
   /*In the end, assign the department*/
   newGuy.department = department;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote