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: 3739308 • 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.

The code I have so far is:

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.PrintWriter;

import java.util.Scanner;

public class CommitteeSelection {

static String [] out = new String [100];

public static void main(String[] args) throws IOException {

Scanner in = new Scanner(System.in);

System.out.println("Enter input file name: ");

String fin= in.nextLine();

System.out.println("Enter output file name: ");

String fout = in.nextLine();

Scanner fileIn = null;

boolean fileFound = false;

while(!fileFound) {

try {

fileIn = new Scanner(new FileInputStream(fin));

fileFound =true;

}catch(FileNotFoundException e) {

System.out.println("Enter input file name: ");

fin= in.nextLine();

}

}

String [][] memberNames;

int numberOfDepartments = fileIn.nextInt();

memberNames = new String [numberOfDepartments][];

String dept = fileIn.nextLine();

//System.out.println(dept);

for(int row=0; row<numberOfDepartments; row++) {

int x = fileIn.nextInt();

memberNames[row] = new String[x];

for(int column =0; column<x; column++) {

String members = fileIn.next();

//System.out.println(members);

memberNames[row][column]= members;

}

}

for(int i=0; i<memberNames.length;i++) {

for(int j =0; j<memberNames[i].length; j++) {

System.out.print(memberNames[i][j]+" ");

}

System.out.println();

}

System.out.println(memberNames.length);

printCommittees(0,0,0, memberNames,fout);

for(int i=0; i<out.length; i++)

System.out.println(out[i]);

fileIn.close();

in.close();

}

public static void printCommittees(int sx, int sy, int index, String [][] memberNames, String fout) {

/*

PrintWriter fileOut = null;

try {

fileOut = new PrintWriter(new FileOutputStream(fout));

}catch(FileNotFoundException e) {

//this won't happen

}

*/

if(sy == memberNames.length) {

//fileOut.println(memberNames[0][0]);

//out[index] += memberNames[sy][i];

return;

}

for(int i=0; i<memberNames[sy].length; i++) {

System.out.println(sy+"|" +memberNames.length);

out[index] += memberNames[sy][i];

printCommittees(i, sy+1, index+1, memberNames,fout);

}

//fileOut.close();

}

}

Explanation / Answer

// Here is your code of the above program .

import java.util.*;
import java.lang.*;

import java.io.*;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.PrintWriter;

import java.util.Scanner;

class MainClass {

public static String [] out = new String [100];

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

Scanner in = new Scanner(System.in);

System.out.println("Enter input file name: ");

String fin= in.nextLine();

System.out.println("Enter output file name: ");

String fout = in.nextLine();

Scanner fileIn = null;

boolean fileFound = false;

while(!fileFound) {

try {

fileIn = new Scanner(new FileInputStream(fin));

fileFound =true;

}catch(FileNotFoundException e) {

System.out.println("Enter input file name: ");

fin= in.nextLine();

}

}

String [][] memberNames;

int numberOfDepartments = fileIn.nextInt();

memberNames = new String [numberOfDepartments][];

String dept = fileIn.nextLine();

System.out.println(dept);

for(int row=0; row<numberOfDepartments; row++) {

int x = fileIn.nextInt();

memberNames[row] = new String[x];

for(int column =0; column<x; column++) {

String members = fileIn.next();

System.out.println(members);

memberNames[row][column]= members;

}

}

for(int i=0; i<memberNames.length;i++) {

for(int j =0; j<memberNames[i].length; j++) {

System.out.print(memberNames[i][j]+" ");

}

System.out.println();

}

System.out.println(memberNames.length);

printCommittees(0,0,0, memberNames,fout);

for(int i=0; i<out.length; i++)

System.out.println(out[i]);

fileIn.close();

in.close();

}

public static void printCommittees(int sx, int sy, int index, String [][] memberNames, String fout) {

PrintWriter fileOut = null;

try {

fileOut = new PrintWriter(new FileOutputStream(fout));

}catch(FileNotFoundException e) {

//this won't happen

}


if(sy == memberNames.length) {

fileOut.println(memberNames[0][0]);

// out[index] += memberNames[sy][i];

return;

}

for(int i=0; i<memberNames[sy].length; i++) {

System.out.println(sy+"|" +memberNames.length);

out[index] += memberNames[sy][i];

printCommittees(i, sy+1, index+1, memberNames,fout);

}

fileOut.close();

}

}