Exemplo n.º 1
0
    private void GenerateVoteDocument(Dictionary <int, int> ElectoralCollegeVotes)
    {
        var jsonList = new List <KeyValuePair <int, int> >();

        foreach (KeyValuePair <int, int> ecv in ElectoralCollegeVotes)
        {
            KeyValuePair <int, int> tempKVP = new KeyValuePair <int, int>(ecv.Key, ecv.Value);
            jsonList.Add(tempKVP);
        }
        StateJsonReader reader = new StateJsonReader();

        reader.writeVoteDocument(jsonList, this);
    }
Exemplo n.º 2
0
    public void calculateCandidateElectors(ElectoralCollegeDistributionType distributionType, string CandidatePath, string StateVotePath)
    {
        StateJsonReader  reader     = new StateJsonReader();
        List <Candidate> candidates = reader.collectCandidates(CandidatePath);

        if (candidates.Count == 0)
        {
            throw new System.InvalidOperationException("There are no candidates present in this election");
        }
        List <VoterPreferences> Votes = collectTheVotes(candidates, StateVotePath);

        OrganizedVotes = OrganizeVotes(candidates, Votes);
        Votes.Clear();
        Dictionary <int, int> ElctoralCollegeVotes = DistributeElectoralCollegePoints(distributionType);

        // TestCode
        // Dictionary<int, Candidate> cans = CandidateDictionaryGenerator(candidates);
        // foreach (KeyValuePair<int, int> cPair in ElctoralCollegeVotes)
        // {
        //     Console.WriteLine(cPair.Key + " won " + cPair.Value + " votes in the great state of " + Name);
        // }
        GenerateVoteDocument(ElctoralCollegeVotes);
    }
Exemplo n.º 3
0
    private List <VoterPreferences> collectTheVotes(List <Candidate> Candidates, string StateVotePath)
    {
        StateJsonReader reader = new StateJsonReader();

        return(reader.collectVotes(this, StateVotePath, Candidates));
    }