Program to Dynamically Allocate Bank Accounts To the Agents/Tellecaller in VB.net

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 750
The below program will do so -

Imports System.Collections.Generic
Imports System.Linq

Namespace ConsoleApplication1
Class Program
Private Shared Sub Main(args As String())
'step 1 - program starts

'Data to be filled on a Case By Case Basis
Dim lstCustomerBankAccounts As New List(Of String)()
'Step 2
'Data to be filled on a Case By Case Basis
Dim lstAgents As New List(Of String)()
'Step 3
Dim countCustomerBankAccounts = lstCustomerBankAccounts.Count
'Step 4
Dim countAgents = lstAgents.Count
'Step 5
Dim repeatCount = countCustomerBankAccounts / countAgents + 1
'Step 6
Dim numberOfAgentsGenerated = Enumerable.Repeat(lstAgents, repeatCount).SelectMany(Function(m) m)
'Step 7
Dim customerBankAccountToAgentMapping = numberOfAgentsGenerated.Zip(lstCustomerBankAccounts, Function(agent, account) New With { _
Key .Agent = agent, _
Key .CustomerBankAccounts = account _
})
'Step 8
Dim groupcustomerBankAccountByAgent = customerBankAccountToAgentMapping.GroupBy(Function(a) a.Agent)
'Step 9
Dim result = groupcustomerBankAccountByAgent.[Select](Function(g) New With { _
Key .Agent = g.Key, _
Key .Accounts = g.[Select](Function(x) x.CustomerBankAccounts).ToList() _
})
For Each r As var In result
Console.WriteLine("Agent Name: " + r.Agent)
For Each cba As var In r.Accounts
Console.WriteLine(" Is holding " + cba)
Next
Console.WriteLine(Environment.NewLine)
Next
'Step 10
Console.ReadKey()
'Step 11
End Sub
End Class
End Namespace


The above program works on the below algorithm

Step 1: Start
Step 2: Get the Customer Bank Accounts list.
Step 3: Get the Agents list.
Step 4: Count of Step 2
Step 5: Count of Step 3

Step 6:
Case 1 : If Count(Step 4) < Count(Step 5) Then Go To Step 7.
Case 2 : If Count(Step 4) = Count(Step 5) Then Go To Step 7.
Case 3 : If Count(Step 4) > Count(Step 5) Then Go To Step 7.

Step 7:
a) Divide Count(Step 4) / Count(Step 5) + 1
b) Number of Agents generated = Repeat of Agents in a Round Robin way till it exhausts Count(Step 5) * (a)

Step 8: Map in a sequential way Step 6 and Step 2 until the smaller of them exhausts.
Step 9: Group Customer Bank Accounts obtained in Step 7 by their Agents.
Step 10: Display.
Step 11: Stop.

Comments or Responses

Login to post response