/**
 * 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  Glenn Young
 * @version 1.0  Date: September 13, 2008
 */
public class TaxCalculator
{
    //constants set to determine the type of item purchased
    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 purchased
     * @param categories  The corresponding categories of all items purchases
     * @return            The tax
     */
    public static double foodTax(double[] prices, int[] categories)
    {
       double tax;
		 
		 //calculate the tax on the total cost of non-prepared 
		 //food items using the foodTax() method in the 
		 //StateTaxes class
		 tax = StateTaxes.foodTax(total(prices, categories, FOOD));

       //returns the amount of tax on non-prepared food items
       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;
       
		 //calculate the tax on the total cost of the non-food items
		 //using the salesTax() method in the StateTaxes class
       tax = StateTaxes.salesTax(total(prices, categories, NON_FOOD));
       
       //return the tax
       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;
       
		 //calculate the tax on the total cost of prepared food items
		 //using the preparedFoodTax() method in the LocalTaxes class
       tax = LocalTaxes.preparedFoodTax(total(prices, categories, PREPARED_FOOD));
       

       //return the value assigned to tax
       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;
       
		 //sets 'total' to 0.0 so values can be added to it
		 total = 0.0;
		 
		 //for loop iterates once for each element in the array
		 for(int i = 0; i < prices.length; i++)
		 {
		         //if block determines if the item is in the 
			      //specified category
		         if(categories[i] == categoryToInclude)
					    //adds the value of the food item in the
						 //specified category to total
                   total = total + prices[i];
		 }
       
       //returns the total value of the items from the
		 //specified category
       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;
       
		 //if block determines if the category is entered is on of the three
		 //possible choices
		 if((category == NON_FOOD) || (category == FOOD) || (category == PREPARED_FOOD))
		     //sets result to true if true if the category is one of the three
			  //possible choices
           result = true;
       else
		     result = false;
			  
		 //returns true if the category is valid, false otherwise
       return result;       
    }//end isValid()
    
}//end TaxCalculator
