In the Programming Exercise Election Results, the class candidatedateType contai
ID: 3640150 • Letter: I
Question
In the Programming Exercise Election Results, the class candidatedateType contains the function calculateTotalVotes. After processing the voting data, this function calculates the total number of votes received by a candidate. The function updateVotesByRegion (of the class candidateType) updates only the number of votes for a particular region.1) Modify the definition of this function so that it also updates the total number of votes received by the candidate. By doing so, the function addVotes in the main program is no longer needed.
2) Modify and run your program with the modified definition of the function updateVotesByRegion
Explanation / Answer
class candidateType{ private int VotesByRegion; private int totalNoOfVotes; //parameterized constructor public candidateType(votesByRegion,totalNoofVotes){ this.VotesByRegion = VotesByRegion; this.totalNoOfVotes = totalNoofVotes; } //TotalVotes method public static int TotalVotes(votesByRegion,totalNoofVotes){ this.VotesByRegion = VotesByRegion; this.totalNoOfVotes = totalNoofVotes; return totalNoOfVotes; } }