/**
 * 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  Anthony Miles
 * @version 1.0
 */
public class TaxCalculator
{
    public static int NON_FOOD        = 0;
    public static int FOOD            = 1;
    public static int PREPARED_FOOD   = 2;
	 public static LocalTaxes localTax = new LocalTaxes(); //Declaration and
	 					//instantiation of the LocalTaxes class so we have access
						//to LocalTaxes methods
	 public static StateTaxes stateTax = new StateTaxes(); //Declaration and
	 					//instantiation of the StateTaxes class so we have access
						//to StateTaxes methods

    /**
     * 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 total;
		 
		 total = 0.0;
		 
       for(int i = 0; i < prices.length; i++ ) //for statement to go
		 					//through the prices array and add them up
		 {
		 	if( categories[i] == FOOD )//if statement to pull out only
							//the category of FOOD from the prices array
		 		total += prices[i];
		 }

		 tax = stateTax.foodTax(total);
		 
       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 total;
		 
		 total = 0.0;
       
       for(int i = 0; i < prices.length; i++ )//for statement to go
		 					//through the prices array and add them up
		 {
		 	if( categories[i] == NON_FOOD )//if statement to pull out only
							//the category of NON_FOOD from the prices array
		 		total += prices[i];
		 }

		 tax = stateTax.salesTax(total);
       
       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 total;
  
  		 total = 0.0;
       
       for(int i = 0; i < prices.length; i++ )//for statement to go
		 					//through the prices array and add them up
		 {
		 	if( categories[i] == PREPARED_FOOD )//if statement to pull out only
							//the category of PREPARED_FOOD from the prices array
		 		total += prices[i];
		 }

		 tax = localTax.preparedFoodTax(total);
       
       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.0;
       
       for(int i = 0; i < prices.length; i++ )//for statement to go
		 					//through the prices array and add them up
		 {
		 	if( categories[i] == categoryToInclude )//if statement to pull out only
							//the categories we want included from the array
		 		total += prices[i];
		 }
       

       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;
		 
		 if( category >= 0 && category <= 2 )//If statement to check
		 			//if the categories that are inputted are valid or not
		 	result = true;
       
       return result;       
    }//end isValid
    
}//end TaxCalculator
