/**
 * A utility class that can be used to calculate sales
 * taxes on a collection of items
 *
 *
 * This work complies with the JMU Honor Code.
 *
 * @author  Jeff Wyman
 * @version 2.0
 */
public class TaxCalculator
{
    public static int NON_FOOD        = 0;
    public static int FOOD            = 1;
    public static int PREPARED_FOOD   = 2;
    

    /**
     * Calculate the tax on the (non-prepared) food items
     *
     * @param prices      The prices of all items purchases
     * @param categories  The corresponding categories of all items purchases
     * @return            The tax
     */
    public static double foodTax(double[] prices, int[] categories)
    {
       double tax = 0.0;
		 int c = 0;
		 
		 for(double i : prices)
		 {
		 	if(categories[c] == 1)
			{
				tax += StateTaxes.foodTax(i);
			}//end if
			c++;
		 }//end for
		 
       return tax;      
    }// end foodTax


    /**
     * Calculate the tax on the non-food items
     *
     * @param prices      The prices of all items purchases
     * @param categories  The corresponding categories of all items purchases
     * @return            The tax
     */
    public static double nonfoodTax(double[] prices, int[] categories)
    {
       double tax = 0.0;
		 int c = 0;
		 
		 for(double i : prices)
		 {
		 	if(categories[c] == 0)
			{
				tax += StateTaxes.salesTax(i);
			}//end if
			c++;
		 }//end for
		 
       return tax;      
    }// end nonfoodTax
    


    /**
     * Calculate the tax on the prepared food items
     *
     * @param prices      The prices of all items purchases
     * @param categories  The corresponding categories of all items purchases
     * @return            The tax
     */
    public static double preparedfoodTax(double[] prices, int[] categories)
    {
       double tax = 0.0;
		 int c = 0;
		 
		 for(double i : prices)
		 {
		 	if(categories[c] == 2)
			{
				tax += LocalTaxes.preparedFoodTax(i);
			}//end if
			c++;
		 }//end for
		 
       return tax;       
    }// end preparedfoodTax



    /**
     * Calculate the total value of all items purchased in
     * particular category
     *
     * @param prices      The prices of all items purchases
     * @param categories  The corresponding categories of all items purchases
     * @param categoryToInclude  The category of interest
     * @return            The total value of items in the given category
     */
    public static double total(double[] prices, int[] categories, 
                                int categoryToInclude)
    {
       double total = 0.0;
		 int c = 0;
		 
		if(categoryToInclude == 0)
		 	for(double i : prices)
			{
				if( categories[c] == 0)
				{
					total += prices[c];
				}// end if
				c++;
			}// end for	
		else if(categoryToInclude == 1)
		 	for(double i : prices)
			{
				if( categories[c] == 1)
				{
					total += prices[c];
				}// end if
				c++;
			}// end for
		else
		 	for(double i : prices)
			{
				if( categories[c] == 2)
				{
					total += prices[c];
				}// end if
				c++;
			}// end for
		 
       return total;       
    }// end total
    
    
    /**
     * Determin if the given category is valid
     *
     * @param category   The category of interest
     * @return           true if the category is valid; false otherwise
     */
    public static boolean isValid(int category)
    {
       boolean     result;
		 
		 if ((category>=0) && (category<=2))
		 	result = true;
   	 else       
     	   result = false;
       
       return result;       
    }// end isValid
    
}// end TaxCalculator
