Question: import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class QueueTester { static Queue queue = new LinkedList(); public static void main(String [] args) {

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class QueueTester
{
static Queue queue = new LinkedList();

public static void main(String [] args)
{
ArrayList groups = new ArrayList();

groups.add("Will Grace");
groups.add("Rachel Ross Phoebe Chandler Monica Joey");
groups.add("Jerry Elaine Kramer George");
groups.add("Beth");

for (int i = 0; i < groups.size(); i++)
{
String group = groups.get(i);
Scanner scanner = new Scanner(group);
while (scanner.hasNext())
{
queue.add(scanner.next());
}
}

System.out.println(getNextGroup(2));
System.out.println(getNextGroup(6));
System.out.println(getNextGroup(4));
System.out.println(getNextGroup(1));
System.out.println(getNextGroup(3));
System.out.println("Expected:[Will, Grace][Rachel, Ross, Phoebe, Chandler, Monica, Joey]");
System.out.println("[Jerry, Elaine, Kramer, George][Beth][]");
}

/*
 * Removes a group of people from a queue.
 * The integer parameter groupMemberSize indicates how many people should be removed from the queue
 * Returns a list of the people in the group
 */
static LinkedList getNextGroup(int groupMemberSize)
{
//-----------Start below here. To do: approximate lines of code = 1
// Create an empty Linked List of Strings to hold the group members

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

//-----------Start below here. To do: approximate lines of code = 6
// Remove groupMemberSize strings (representing the names of people in the group) from the queue
// and add each name string to the list
// Hint: if the queue is empty then return an empty group list


//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
}

P.S: please double confirm output is same as expected.

Step by Step Solution

3.48 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

In the getNextGroup method we basically have to remove groupMemberSize number of strings from the queue and return it in the form of a LinkedList of s... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!