/**
 * 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  Kyle Ames
 * @version 1.0	Date: September 10, 2008
 */
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;
       double value;
		 
		 value = 0.0;
		 
       for (int i = 0; i < categories.length; i++)
		 	{
			 if (categories[i] == 1)
			 	value += prices[i];
			}
		 
		 tax = StateTaxes.foodTax(value);
       


       return tax;       
    }


    /**
     * 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;
       double value;
		 
		 value = 0.0;
		 
       for (int i = 0; i  < categories.length; i++)
		 	{
			 if (categories[i] == 0)
				value += prices[i];
			}	
       
		 tax = StateTaxes.salesTax(value);
       


       return tax;       
    }
    


    /**
     * 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;
       double value;
		 
		 value = 0.0;
       for (int i = 0; i  < categories.length; i++)
		 	{
			 if (categories[i] == 2)
				value += prices[i];
			}	
		 tax = LocalTaxes.preparedFoodTax(value);
       


       return tax;       
    }



    /**
     * 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;
       double		value;
		 
		 total = 0.0;
		 value = 0.0;
		 
		 for (int i = 0; i < categories.length; i++)
		 	{
			 if (categories[i] == categoryToInclude)
				total += prices[i];
    		}   

       return 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 == 1) || (category == 2) || (category == 0))
		 	result = true;
       else
		 	result = false;
       
		 return result;       
    }
    
}
