/**
 * An accident report.
 *
 * This version implements the Ordered interface
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 2.0
 */

public class AccidentReport implements Ordered, Prioritized
{
    private int     size;
    private String  type;


    /**
     * Explicit Value Constructor.
     *
     * @param type   The type of accident
     * @param size   The number of vehicles involved
     */
    public AccidentReport(String type, int size)
    {
	this.type = type;
        this.size = size;
    }

    /**
     * Compares this Ordered Object with the given Ordered Object 
     * (required by Ordered).
     *
     * @param other   The Object to compare
     * @return -1/0/1 if this is less than/equal to/before other
     */
    public int compareTo(Ordered other)
    {
        // This is a risky typecast. We will discuss ways
        // of correcting it later.
        AccidentReport ar = (AccidentReport)other;
        
        if      (this.size == ar.size) return  0;
        else if (this.size  < ar.size) return -1;
        else                           return  1;
    }

    /**
     * Return the priority of this AccidentReport (required by
     * Prioritized).
     *
     * @return   The priority of this AccidentReport
     */
    public int getPriority()
    {
	int priority;


	if (size > 3) priority = 5;
        else if (size > 5) priority = 10;
	else if (type.equals("HEAD ON")) priority = 8;
	else priority = 3;

	return priority;
    }

    /**
     * Set the size of the accident.
     *
     * @param size   The number of vehicles involved
     */
    public void setSize(int size)
    {
	this.size = size;
    }

    /**
     * Get a String representation of this AccidentReport.
     *
     * @return  The String representation
     */
    public String toString()
    {
        return type + "\t" + size;
    }
    
}
