So the issue I'm having is for the program to print out every value that holds a certain key. The program asks the user what department they want to see the employee roster for. The user then picks and what department they want to see and enters the value printed next to the department, lets say they chose "4. accounting". The program then needs to print out all the values that are associated with that key. in the format of "Employees in accounting: employee 1, employee 2, etc. . It's also supposed to use the method countEmps. What I specifically need help with is the syntax to make the program take the values that have the desired key and print them out. Any help is appreciated!
import java.util.ArrayList;
import java.util.HashMap;
public class Department{
ArrayList<Employee> countEmps(HashMap <String, Employee> e , int I, ArrayList<Employee> l){
return l;
}
}
import java.util.Scanner;
import java.util.*;
public class empCountDriver {
public static void main(String[] args) {
Map <String, Employee> empMap = new HashMap<>();
int menuselect = 0;
Scanner key = new Scanner(System.in);
Employee emp1 = new Employee (101,2 ,3 , "John", "Joe");
Employee emp2 = new Employee (102,5 ,6 , "Phil", "Jognson");
Employee emp3 = new Employee (103,4 ,7 , "Billy", "Schmitz");
Employee emp4 = new Employee (104,3 ,3 , "Hank", "Dugart");
Employee emp5 = new Employee (105,1 ,2 , "Able", "Philstein");
Employee emp6 = new Employee (106,3 ,10 , "Adam", "Renolds");
Employee emp7 = new Employee (107,1 ,4 , "Larry", "Cableguy");
Employee emp8 = new Employee (108,5 ,2 , "Doug", "Dougster");
Employee emp9 = new Employee (109,2 ,3 , "Mylan", "Ester");
Employee emp10 = new Employee (110,5 ,6 , "Cherry", "Jakesn");
Employee emp11 = new Employee (111,2 ,3 , "Ethel", "Manfred");
Employee emp12 = new Employee (112,3 ,11 , "Lindsey", "Joel");
Employee emp13 = new Employee (113,1,1 , "Ellie", "Winston");
Employee emp14 = new Employee (114,4 ,6 , "Blake", "Wiotell");
Employee emp15 = new Employee (115,1 ,3 , "Elton", "John");
Employee emp16 = new Employee (116,2 ,7 , "David", "Flint");
Employee emp17 = new Employee (117,4 ,600000 , "Igor", "TheElder");
Employee emp18 = new Employee (118,5 ,9 , "Hanz", "Joe");
Employee emp19 = new Employee (119,2 ,3 , "Jordan", "Friedel");
Employee emp20 = new Employee (120,2 ,3 , "Dyaln", "Rogers");
empMap.put("2", emp1);
empMap.put("5", emp2);
empMap.put("4", emp3);
empMap.put("3", emp4);
empMap.put("1", emp5);
empMap.put("3", emp6);
empMap.put("1", emp7);
empMap.put("5", emp8);
empMap.put("2", emp9);
empMap.put("5", emp10);
empMap.put("2", emp11);
empMap.put("3", emp12);
empMap.put("1", emp13);
empMap.put("4", emp14);
empMap.put("1", emp15);
empMap.put("2", emp16);
empMap.put("4", emp17);
empMap.put("5", emp18);
empMap.put("2", emp19);
empMap.put("2", emp20);
menus();
menuselect = key.nextInt();
while (menuselect!= 6){
//if the user enters 1 it will print out all the employees with the key of 1, if the user enters 2
//it will print out all the employees with the key of 2 and so on.
}
}
public static void menus(){
System.out.println("Company Departments:");
System.out.println("1. IS");
System.out.println("2. Accounting");
System.out.println("3. Purchasing");
System.out.println("4. Sales");
System.out.println("5. Advertising");
System.out.println("6. EXIT");
}
}
The Employee class:
public class Employee {
private int employeeID;
private int departmentID;
private int employedYears;
private String firstName;
private String lastName;
public Employee ( int eid, int d, int y, String fn, String ln){
employeeID = eid;
departmentID = d;
employedYears = y;
firstName = fn;
lastName = ln;
}
public void setEmployeeID (int EmployeeID){
employeeID = EmployeeID;
}
public int getEmployeeID(){
return employeeID;
}
public void setDepartmentID (int DepartmentID){
departmentID = DepartmentID;
}
public int getDepartmentID(){
return departmentID;
}
public void setEmployedYears(int EmployedYears){
employedYears = EmployedYears;
}
public int getEmployedyears(){
return employedYears;
}
public void setFirstName (String FirstName){
firstName = FirstName;
}
public String getFirstName (){
return firstName;
}
public void setLastName (String LastName){
lastName = LastName;
}
public String getLastName (){
return lastName;
}
}