DEV Community

mohamed Tayel
mohamed Tayel

Posted on

1

Article 3: Building a Team Assignment Application with Grid Formatting and Shuffling

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:

  1. Randomizes a list of employees into teams.
  2. 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

  1. Integration of Utilities:

    • Combine the GridFormatter and Shuffler to solve a real-world problem.
  2. Dynamic Team Assignment:

    • Randomize a list of employees and split them into teams of a specified size.
  3. Modularity:

    • Leverage reusable components (GridFormatter and Shuffler) for clean and maintainable code.

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)}");
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Step 3: Run the Application

Input:

Employees: Alice, Bob, Charlie, Diana, Eve, Frank, Grace, Hank, Ivy, Jack
Team Size: 3
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

How It Works

  1. Randomizing Employee List:

    • The Shuffler utility randomizes the employee list, ensuring fair and unbiased team assignments.
  2. Formatting with GridFormatter:

    • The GridFormatter displays the original and shuffled lists in a neat grid for better readability.
  3. Dynamic Team Assignment:

    • Employees are split into teams based on the specified team size, with the remaining employees assigned to the last team.

Takeaways

  1. Integration of Reusable Utilities:

    • By combining the GridFormatter and Shuffler, we’ve built a modular and dynamic solution.
  2. Real-World Application:

    • This example demonstrates how to use reusable components to solve practical problems.
  3. 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:

  1. Export Team Assignments:
    • Save the results to a CSV or text file.
  2. Add Validation:
    • Handle edge cases, such as empty employee lists or invalid team sizes.
  3. Interactive Input:
    • Allow users to input employee names and team sizes dynamically.

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more