/**
 * 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  Jake Carey
 * @version 1.0, September 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 added, tax;
       	
			added = 0.0;
         tax 	= 0.0;
     		
			for (int i = 0; i < prices.length; i++)
			{ 	
	 			if(categories[i] == FOOD)
	         {
					added += prices[i];
	         }//end else if
			}//end for
			
			//calculates the tax for food items
			tax = StateTaxes.foodTax(added);	
			
         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 added, tax;
       	
			added = 0.0;
         tax 	= 0.0;
			
			//Adds up the prices of nonfood items
       	for (int i = 0; i < prices.length; i++)
			{	
				if (categories[i] == NON_FOOD)
		      {	
					added += prices[i];
		      }//end if
			}//end for
			
			//calculates the tax of the nonfood items
			tax = StateTaxes.salesTax(added);
			
         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 added, tax;
       	
			added = 0.0;
         tax 	= 0.0;
   
			for (int i = 0; i < prices.length; i++)
			{
				if(categories[i] == PREPARED_FOOD)
	         {		
					added += prices[i];
	         }//end else if
			}//end for
			
			//calculates the tax of the preparedfood items
			tax = LocalTaxes.preparedFoodTax(added);
			
         return tax;       
      }//end preparedfoodTax
   
   
   
    /**
     * Calculate the total value of all items purchased in
     * particular category
     *
     * @param prices      The prices of all items purchased
     * @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;
      	
      	//This determines which category to use and calculates the total
      	// tax accordingly.			
	         if (categoryToInclude == NON_FOOD)
	         {
					total = nonfoodTax(prices, categories);
	         }//end if
	         else if(categoryToInclude == FOOD)
	         {
					total = foodTax(prices, categories);
	         }//end else if
	         else if(categoryToInclude == PREPARED_FOOD)
	         {
					total = preparedfoodTax(prices, categories);
	         }//end else if
      
         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;
       
         result = false;
       
       //This determines whether or not the choice given by the user
       // is valid or not.
         if ((category >= 0) & (category <=2))
            result = true;
         else
            result = false;
       
         return result;       
      }//end isValid  
   }//end TaxCalculator
