/**
 * Class that contains debate information on a candidate.
 *   @author Dave Reed
 *   @version 1/22/16
 */
public class Candidate implements Comparable<Candidate> {
    private String name;
    private double total;
    private int numPositive;
    private int numNegative;
    
    /**
     * Constructs a candidate with initialized stats.
     *   @param name the candidate's name (containing no spaces)
     */
    public Candidate(String name) {
        this.name = name;
        this.total = 0;
        this.numPositive = 0;
        this.numNegative = 0;
    }
    
    /**
     * Accesses the candidate's name.
     *   @return the name
     */
    public String getName() {
        return this.name;
    }

    /**
     * Accesses the candidate's score total.
     *   @return the total
     */
    public double getTotal() {
        return this.total;
    }
    
    /**
     * Accesses the number of positive scores received.
     *   @return the number of positives
     */
    public int getPositive() {
        return this.numPositive;
    }

    /**
     * Accesses the number of negative scores received.
     *   @return the number of negatives
     */
    public int getNegative() {
        return this.numNegative;
    }
        
    /**
     * Records a viewer's score for the candidate.
     *   @param rating the score to be recorded
     */
    public void record(double rating) {
        this.total += rating;
        if (rating > 0) { 
            this.numPositive++;
        }
        else if (rating < 0) {
            this.numNegative++;
        }
    }
    
    /**
     * Converts the candidate info into a String.
     *   @return the String representation
     */
    public String toString() {
        return String.format("%-10s %8.1f %8d %8d", name, this.total,
                              this.numPositive, this.numNegative);
    }
    
    /**
     * Comparison operation for candidates.
     *   @param other the other candidate to be compared to
     *   @return negative if less; 0 if equal; positive if greater
     */
    public int compareTo(Candidate other) {
        if (this.total != other.total) {
            return (int)(other.total - this.total);
        }
        else {
            return this.name.compareTo(other.name);
        }
    }
}
