/**
 * 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  Tom Kowaleski
 * @version 1.3
 */
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;
		 double value;
       
		 //as long as there are more values in the array, 
		 // the for loop iterates
		 for (int index = 0; index < categories.length; index++)
		 {
		 	// whenever the category is food(1), the tax is calculated for it
		    if (categories[index] == 1)
			 {
			    value = prices[index];
			    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 = 0.0;
		 double value;
      
		 //for loop iterates as long as there are values in the array 
		 for (int index = 0; index < categories.length; index++)
		 {
		 	 //whenever the category is non-food(0), 
			 // the tax is calculated for it
		    if (categories[index] == 0)
			 {
			 	 //tax is calculated through the StateTaxes class for
				 // all the non-food items
			    value = prices[index];
			    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 = 0.0;
		 double value;
       
		 for (int index = 0; index < categories.length; index++)
		 {
		    if (categories[index] == 2)
			 {
			    value = prices[index];
			    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;
		 total = 0.00;
       
		 //for loop iterates and adds up all the categorys to include
		 for (int i = 0; i < categories.length; i++)
		 {
		 	if (categories[i] == categoryToInclude)
				total += prices[i];
		 }
   
       

       return total;       
    }
    
    
    /**
     * Determine 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;
       
		 //checking to make sure the category is valid ie
		 // whether it is 0, 1, or 2
		 if ((category == 0) || (category == 1) || (category == 2))
       	result = true;
       
		 else
		 	//if the category entered is not valid, returns false
		 	result = false;
		 
       return result;       
    }
    
}
