Introduction
Now that we’ve built the GridFormatter and Shuffler utilities, it’s time to put them together in a real-world application. In this article, we’ll create a Team Assignment Application that:
- Randomizes a list of employees into teams.
- Displays the employee list and team assignments in a clean, grid-based format.
By the end of this article, you’ll:
- Understand how to integrate reusable utilities.
- Build a practical application with dynamic features.
Key Concepts
- 
Integration of Utilities: - Combine the GridFormatterandShufflerto solve a real-world problem.
 
- Combine the 
- 
Dynamic Team Assignment: - Randomize a list of employees and split them into teams of a specified size.
 
- 
Modularity: - Leverage reusable components (GridFormatterandShuffler) for clean and maintainable code.
 
- Leverage reusable components (
Step-by-Step Implementation
Step 1: Setup the Application
Start by setting up the project and referencing the Utilities namespace, which includes the GridFormatter and Shuffler utilities created in the previous articles.
Step 2: Implement the Team Assignment Application
Here’s the full implementation:
using System;
using System.Collections.Generic;
using Utilities;
class Program
{
    static void Main(string[] args)
    {
        // Step 1: Input employee names
        var employees = new List<string>
        {
            "Alice", "Bob", "Charlie", "Diana", "Eve", "Frank", "Grace", "Hank", "Ivy", "Jack"
        };
        Console.WriteLine("Original Employee List:");
        PrintGrid(employees, 40, 4);
        // Step 2: Shuffle employees for random team assignments
        var shuffledEmployees = employees.Shuffle().ToList();
        Console.WriteLine("\nShuffled Employee List:");
        PrintGrid(shuffledEmployees, 40, 4);
        // Step 3: Assign teams and display them
        Console.WriteLine("\nTeam Assignments:");
        AssignTeams(shuffledEmployees, 3);
    }
    static void PrintGrid(IEnumerable<string> data, int totalWidth, int gapWidth)
    {
        // Use the GridFormatter to display the data in a grid format
        var formatter = new GridFormatter<string>(data);
        foreach (var row in formatter.FormatGrid(totalWidth, gapWidth))
        {
            Console.WriteLine(row);
        }
    }
    static void AssignTeams(List<string> employees, int teamSize)
    {
        int teamCount = (int)Math.Ceiling((double)employees.Count / teamSize);
        for (int i = 0; i < teamCount; i++)
        {
            // Take the next batch of employees for the current team
            var team = employees.Skip(i * teamSize).Take(teamSize);
            Console.WriteLine($"Team {i + 1}: {string.Join(", ", team)}");
        }
    }
}
Step 3: Run the Application
Input:
Employees: Alice, Bob, Charlie, Diana, Eve, Frank, Grace, Hank, Ivy, Jack
Team Size: 3
Output:
Original Employee List:
Alice      Bob        Charlie    Diana     
Eve        Frank      Grace      Hank      
Ivy        Jack                           
Shuffled Employee List:
Frank      Diana      Eve        Hank      
Grace      Jack       Charlie    Alice     
Ivy        Bob                           
Team Assignments:
Team 1: Frank, Diana, Eve
Team 2: Hank, Grace, Jack
Team 3: Charlie, Alice, Ivy
Team 4: Bob
How It Works
- 
Randomizing Employee List: - The Shufflerutility randomizes the employee list, ensuring fair and unbiased team assignments.
 
- The 
- 
Formatting with GridFormatter: - The GridFormatterdisplays the original and shuffled lists in a neat grid for better readability.
 
- The 
- 
Dynamic Team Assignment: - Employees are split into teams based on the specified team size, with the remaining employees assigned to the last team.
 
Takeaways
- 
Integration of Reusable Utilities: - By combining the GridFormatterandShuffler, we’ve built a modular and dynamic solution.
 
- By combining the 
- 
Real-World Application: - This example demonstrates how to use reusable components to solve practical problems.
 
- 
Flexibility: - The solution is adaptable to different datasets, widths, and team sizes.
 
What’s Next?
Now that you’ve built the Team Assignment Application, here are some ideas to extend the project:
- 
Export Team Assignments:
- Save the results to a CSV or text file.
 
- 
Add Validation:
- Handle edge cases, such as empty employee lists or invalid team sizes.
 
- 
Interactive Input:
- Allow users to input employee names and team sizes dynamically.
 
 

 
    
Top comments (0)