Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please complete this with comments and pseudo code. Design and implement a progr

ID: 3867040 • Letter: P

Question

Please complete this with comments and pseudo code.

Design and implement a program processes voting data of presidential election for the country of RichlandCollege where the said country consists of 4 states. At this time, there are 6 candidates are running for the position as seen in the candData.txt text file. The results of the votes are sent to you for processing, see sample in voteData.txt. It lists each candidate's name and the votes they received by states. You should have a nicely formatted output of the election results with the winner's name printed.

voteData.txt
Your program driver should generate a randomly generated voteData based on the given candidate names, random state selection ( 1 - 4 ), and random votes ( 0 - 50 ) per state.
You should generate 10,000 - 1,000,000 entries in the voteData.txt before processing the data. In your design ( UML/Flowchart, UML/pseudo code ) have a BigO analysis for your algorithms ( where it applies ) and justify your selection of algorithms based on speed and storage characteristics.



Candidate
This class implements a candidate as an object.


Methods ( besides standard methods, implement the specific methods especially their post condition requirements )

public void method_name_chsen_by_you(int state, int votes)
Method to set the votes of a candidate for a particular state.
Postcondition: The votes specified by the parameter votes are assigned to the state specified by the parameter state.

public void method_name_chsen_by_you(int state, int votes)
Method to update the votes of a candidate for a particular state.
Postcondition: The votes specified by the parameter votes are added to the state specified by the parameter state.

public boolean method_name_chsen_by_you(Candidate otherCan)
Method to determine if two candidates have the same name.
Postcondition: Returns true if the name of this candidate is the same as the name of the candidate specified by the parameter otherCan.

public int method_name_chsen_by_you(Candidate otherCan)
Method to compare the names of two candidates.
Postcondition: Returns 0 if the name of this candidate is the same as the name of otherCan; returns < 0 if the name of this candidate is less then the name of otherCan; returns > 0 if the name of this candidate is greater than the name of otherCan.

ElectionResult
This class contains methods for processing voting data for presidential election.

Methods ( besides standard methods, implement the specific methods especially their post condition requirements )

public static void method_name_chsen_by_you(Candidate[] list, int length)
Algorithm post condition: list objects are in ascending order.

public static int method_name_chsen_by_you(Candidate[] list, int length,Candidate searchItem)
Algorithm post condition: If searchItem is found in the list,it returns the location of searchItem; otherwise it returns -1.

candData.txt :

voteData.txt:

Candidate ElectionResult TestProgElectionResult

Explanation / Answer

public class Candidate {
    private int[] stateVotes; //holds the votes gained state wise
    private String name; //name of the candidate
    public void setVotes(int state, int votes) { //set votes of a particular state
        stateVotes[state - 1] = votes;
    }
  
    public void updateVotes(int state, int votes) { //updates votes of a state
        stateVotes[state - 1] += votes;
    }
  
    public boolean equals(Candidate otherCan) { // compares two candidates with respect to name if equal
        return name.equals(otherCan.name);
    }
  
    public int compareTo(Candidate otherCan) { // compares two candidates with respect to name
        return name.compareTo(otherCan.name);
    }
  
}


class ElectionResult {
    public static void sortList(Candidate[] list, int length) { //sorts the candidate list using bubble sort
        for (int i = 0; i < length - 1; i++) //bubble sort the list
            for (int j = 0; j < length - 1 - i; j++)
                if (list[j].compareTo(list[j+1]) > 0) {
                    Candidate tmp = list[j];
                    list[j] = list[j + 1];
                    list[j+1] = tmp;
                }
    }
  
    public static int search(Candidate[] list, int length,Candidate searchItem) { //search a candidate from a given list of candidates
        for (int i = 0; i < length; i ++)
            if (list[i].equals(searchItem))
                return i;
        return -1;
    }
}

Do you need anything more? if so, please let me know...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote