/**
 * 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  Jimmy Tessitore
 * @version 1.0  September 9, 2008
 */
    public class TaxCalculator
   {
    //Declarations and initializations of final static variables
    //Used as category labels
      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)
      {
      //Declaration
         double tax;
      	
      	//Initialization
         tax = 0.0;
         
         for(int i=0; i<categories.length; i++)
         //Loop to determine which array slot is correct for the food tax
            if(categories[i] == FOOD)
            {
            //Checks array location at 0
               tax += StateTaxes.foodTax(prices[i]);
            }	
      
      //Returns tax for non-prepared food items
         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)
      {
      //Declaration
         double tax;
      	
       //Initialization
         tax = 0.0;
      	
      	//Loop to determine which array slot is correct for the non-food tax
         for(int i=0; i<categories.length; i++)
         //Loop to determine which array slot is correct for the food tax
            if(categories[i] == NON_FOOD)
            {
            //Checks array location at 0
               tax += StateTaxes.salesTax(prices[i]);
            }	
      	
      //Returns tax for non food items
         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)
      {
      //Declaration
         double tax;
       
       //Initialization
         tax = 0.0;
       
         //Loop to determine which array slot is correct for the prepared food tax
         for(int i=0; i<categories.length; i++)
         //Loop to determine which array slot is correct for the food tax
            if(categories[i] == PREPARED_FOOD)
            {
            //Checks array location at 0
               tax += LocalTaxes.preparedFoodTax(prices[i]);
            }	
      
      //Returns tax for prepared food items
         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)
      {
      //Declaration
         double     total;
       
       //Initialization
         total = 0.00;
      	
      	//Loops determine which method to call based on the category chosen
         if(categories[0] == categoryToInclude)
         {
            if(categoryToInclude == 0)
            {
               //Takes in all the prices of the array
               for(int p=0; p<prices.length; p++)
                  total = prices[0];
            }
            if(categoryToInclude == 1)
            {
               //Takes in all the prices of the array
               for(int p=0; p<prices.length; p++)
                  total = prices[1];
            }
            if(categoryToInclude == 2)
            {
               //Takes in all the prices of the array
               for(int p=0; p<prices.length; p++)
                  total = prices[2];
            }		
         }
         
         else if(categories[1] == categoryToInclude)
         {
            if(categoryToInclude == 0)
            {
               //Takes in all the prices of the array
               for(int p=0; p<prices.length; p++)
                  total = prices[0];
            }
            if(categoryToInclude == 1)
            {
               //Takes in all the prices of the array
               for(int p=0; p<prices.length; p++)
                  total = prices[1];
            }
            if(categoryToInclude == 2)
            {
               //Takes in all the prices of the array
               for(int p=0; p<prices.length; p++)
                  total = prices[2];
            }
         }
         
         else if(categories[2] == categoryToInclude)
         {
            if(categoryToInclude == 0)
            {
               //Takes in all the prices of the array
               for(int p=0; p<prices.length; p++)
                  total = prices[0];
            }
            if(categoryToInclude == 1)
            {
               //Takes in all the prices of the array
               for(int p=0; p<prices.length; p++)
                  total = prices[1];
            }
            if(categoryToInclude == 2)
            {
               //Takes in all the prices of the array
               for(int p=0; p<prices.length; p++)
                  total = prices[2];
            }
         }
         
         else
         {
         //Safeguard to show that the program messed up
            total = -999;
         }
      
      //Returns total tax of particular category
         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)
      {
      //Declaration
         boolean     result;
      	
       //Initialization of boolean
       //Used as a check to see if it is valid - if not it will remain false
         result = false;
      	
      	//Loop to determine if the category is valid
         if(category == 0 || category == 1 || category == 2)
            result = true;
       
       //Returns true/false depending on if the category is valid
         return result;       
      }
    
   }//end TaxCalculator
