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

The provost at Eastminster College wants to form a committee to determine if the

ID: 3735419 • Letter: T

Question

The provost at Eastminster College wants to form a committee to determine if they have too many committees on the college. She intends to select one faculty member from each department but is unsure of which selections would make the best committee. She has asked you to write a program that will output all possible committees that could be formed. For example, if there were only three departments with the following members Anthropology Biometrics Ceraics Andy, Bob, Carole Alice Artie, Cindy then the six possible committees would be Andy, Alice, Artie Andy, Alice, Cindy Bob, Alice, Artie Bob, Alice, Cindy Carole, Alice, Artie Carole, Alice, Cindy Input Input should be from a text file with the following format: the first line will contain an integer n indicating the number of departments followed by the n names of the departments. Each line after that will contain a department description. These descriptions will start with an integer m indicating the number of members of the department, followed by the m names of the department members. Each name wil be a single, alphabetic string. Two possible input files for the example given above are 3 Anthropology Biometrics Ceramics 3 Andy Bob Carole 1 Alice 2 Artie Cindy 3 Biometrics Ceramics Anthropology 1 Alice 2 Cindy Artie 3 Carole Andy Bob Your program should prompt the user for the name of the input file Output Outputthe total number of committees followed by a list of each committee, one com mittee per line. The first person in each committee listing should come from the department whose name comes first alphabetically; the second person should come from the department whose name comes second alphabetically, and so on. All committees should be output in lexicographic order. For example, the output using either of the two input files shown above should look like: 6 committees: Andy, Alice, Artie Andy, Alice, Cindy Bob, Alice, Artie Bob, Alice, Cindy Carole, Alice, Artie Carole, Alice, Cindy

Explanation / Answer

import java.util.*;

import java.lang.*;

import java.io.*;

public class MainClass

{

public static void main (String[] args) throws java.lang.Exception

{

Scanner sc=new Scanner(System.in);// instead of system.in , give your file path here

Map<String,ArrayList<String>> map = new HashMap<>();

int noOfDepartment=sc.nextInt();

List<String> departmentList=new ArrayList<>();

for(int i=0;i<noOfDepartment;i++)

{

departmentList.add(sc.next());

}

int totalCommittees = 1;

for(int i=0;i<departmentList.size();i++)

{

int totalMembers = sc.nextInt();

totalCommittees*=totalMembers;

ArrayList<String> arrayList=new ArrayList<>();

for(int j=0;j<totalMembers;j++)

{

arrayList.add(sc.next());

}

Collections.sort(arrayList);

map.put(departmentList.get(i),arrayList);

}

  

Collections.sort(departmentList);

System.out.println(totalCommittees+" committees:");

printCommittees(departmentList,map,0,"");

  

  

}

public static void printCommittees(List<String> list,Map<String,ArrayList<String>> map, int i,String sub)

{

if(i>=list.size())

return;

String dep=list.get(i);

ArrayList<String> memList=map.get(dep);

for(int x=0;x<memList.size();x++)

{

if(i+1<list.size())

printCommittees(list,map,i+1,sub+memList.get(x)+", ");

else

System.out.println(sub+memList.get(x));

  

  

}

}

}