/**
 * 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  Hunter McMillen
 * @version 1.0 - 9/8/08
 */
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;
       tax = 0;
       
		 //searches through the entire prices array
		 //if it finds an entry with a food category
		 //the method calculates the tax on it
       for(int i = 0; i < prices.length; i++)
       {
           if(isValid(categories[i]) && categories[i] == 1)
           {
			  	   tax = StateTaxes.foodTax(prices[i]);
           } //end if
       }//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;
       tax = 0.0;
       
		 //searches through the entire prices array
		 //if it finds an entry with a non food category
		 //the method calculates the tax on it
		 for(int i = 0; i < prices.length; i++)
       {
           if(isValid(categories[i]) && categories[i] == 0)
           {
			  	   tax = StateTaxes.salesTax(prices[i]);
           }//end if
       }//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;
       tax = 0.0;
       
		 //searches through the entire prices array
		 //if it finds an entry with a prepared food category
		 //the method calculates the tax on it
		 for(int i = 0; i < prices.length; i++)
       {
           if(isValid(categories[i]) && categories[i] == 2)
           {
			  	   tax = LocalTaxes.preparedFoodTax(prices[i]);
           }//end if
       }//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;
       total = 0.00;
		 
		 //searches the entire array and adds the 
		 //total price of each item in each category 
		 //to the total value of that category
		 for(int i = 0; i < prices.length; i++)
		 {
		 	if(isValid(categories[i]) && categories[i] == 0 &&
			categoryToInclude == 0)
			{
				total = total + prices[i];
			}
			else if(isValid(categories[i]) && categories[i] == 1 &&
			categoryToInclude == 1)
			{
				total = total + prices[i];
			}
			else if(isValid(categories[i]) && categories[i] == 2 && 
			categoryToInclude == 2)
			{
				total = total + prices[i];
			}//end if
		 }//end for

       return total;       
    }//end 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;
       
       //checks to see if the category is a valid category
       //if valid method returns true
       if(category == 0 || category == 1 || category == 2)
       {
           result = true;
       }
       else
       {
           result = false;
       }//end if
       
       return result;       
    }//end boolean
}//end taxCalculator
