// Function to perform the calculations according to the D'Hondt method private static void DhondtCalculations(List <Incumbent> parties, int seatsElected) { // Describe the first party to hold the most votes in the election Incumbent greatestVotes = parties.Aggregate((v1, v2) => v1.VoteTally > v2.VoteTally ? v1 : v2); greatestVotes.SeatScore += 1; greatestVotes.DhondtCalculation(); // Continue the loop until all possible incumbents have been elected int totalSeatsElected = 0; while (totalSeatsElected != seatsElected) { // If the amount of seats has not been reached, the progrram will reset the variable totalSeatsElected = 0; Incumbent maxVotes = parties.Aggregate((v1, v2) => v1.ChangedVotes > v2.ChangedVotes ? v1 : v2); maxVotes.SeatScore += 1; maxVotes.DhondtCalculation(); foreach (Incumbent p in parties) { totalSeatsElected += p.SeatScore; } } Console.WriteLine($"\nThe {seatsElected} seats that were awarded are:"); }
private static List <Incumbent> FindData(string exactpath) { // Extract the data from the file and assort the values in to a list List <string> dataSource = File.ReadAllLines(exactpath).ToList(); List <Incumbent> parties = new List <Incumbent>(); foreach (string line in dataSource.Skip(3)) { string[] dataParts = line.Split(','); Incumbent p = new Incumbent(dataParts[0], Convert.ToInt32(dataParts[1]), dataParts.Skip(2).ToArray()); parties.Add(p); } return(parties); }