/**
 * 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  Matt Serone
 * @version 1.5 Date - Sept. 16, 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 sum;
       
       tax = 0.0;
       sum = 0.0;
       
       for(int x = 0; x < prices.length; x++)
       //for each of the values in the array prices
       {
       	  if(categories[x] == FOOD)
       	  //if it is the FOOD category
       	  {
       	  	sum += prices[x];
       	  	//sum adds up all of the values in the
       	  	//prices array that are in that category
       	  }//end if
       }//end for
       
	   tax = StateTaxes.foodTax(sum);
	   //tax is applied to the sum of the values

       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;
       double sum;
       
       tax = 0.0;
       sum = 0.0;
       
	   for(int x = 0; x < prices.length; x++)
	   //for each of the values in the array prices
	   {
	   	   if(categories[x] == NON_FOOD)
	   	   //if it is the NON_FOOD category
	   	   {
	   	   	  sum += prices[x];
	   	   	  //sum adds up all of the values in the
       	  	  //prices array that are in that category
	   	   }//end if
	   }//end for
	   
	   tax = StateTaxes.salesTax(sum);
	   //tax is applied to the sum of the values

       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;
       double sum;
       
       tax = 0.0;
       sum = 0.0;
       
       for(int x = 0; x < prices.length; x++)
       //for each of the values in the array prices
       {
       	   if(categories[x] == PREPARED_FOOD)
       	   //if it is the PREPARED_FOOD category
       	   {
       	   	   sum += prices[x];
       	   	   //sum adds up all of the values in the
       	  	   //prices array that are in that category
       	   }//end if
       }//end for
       
	   tax = LocalTaxes.preparedFoodTax(sum);
	   //tax is applied to the sum of the values

       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;
       
       if(categoryToInclude == NON_FOOD)
       //if the category matches
       {
       	   for(int x = 0; x < prices.length; x++)
       	   {
       	   	   if(categories[x] == NON_FOOD)
       	   	   	   total += prices[x];
       	   	   //if the category matches then
       	   	   //the total is summed up
       	   }//end for
       }//end if
       else if(categoryToInclude == FOOD)
       //if the category matches
       {
       	   for(int x = 0; x < prices.length; x++)
       	   {
       	   	   if(categories[x] == FOOD)
       	   	   	   total += prices[x];
       	   	   //if the category matches then
       	   	   //the total is summed up
       	   }//end for
       }//end else if #1
       else if(categoryToInclude == PREPARED_FOOD)
       //if the category matches
       {
       	   for(int x = 0; x < prices.length; x++)
       	   {
       	   	   if(categories[x] == PREPARED_FOOD)
       	   	   	   total += prices[x];
       	   	   //if the category matches then
       	   	   //the total is summed up
       	   }//end for
       }//end else if #2
       
       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;
       
       result = false;
       if(category == NON_FOOD || category == FOOD
       	  || category == PREPARED_FOOD)
       //if the category is one of the ones that
       //is specified then the result is true
       		 result = true;	
       
       return result;       
    }//end isValid()
    
}//end TaxCalculator class
