/**
 * 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  DAT NGUYEN
 * @version 1.0
 */
public class TaxCalculator
{
	//class static variables
	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)
	{
		//local variables
		double tax;
		double totalPrice;
		
		//initialize variables 
		tax = 0.0;
		totalPrice = 0.0;
		
		//calls total method to get the total for food items
		totalPrice = total(prices, categories, FOOD);
		
		//calculates the sales tax for food items				
		tax = StateTaxes.foodTax(totalPrice);
		
		//returns the calculated tax
		return tax;       
	} //end foodTax method

	/**
	 * 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)
	{
		//local variables
		double tax;
		double totalPrice;
		 
		//initialize variables
		tax = 0.0;
		totalPrice = 0.0;
		 
		//calls total method to get the total for non_food items
		totalPrice = total(prices, categories, NON_FOOD);
		
		//calculates the sales tax for non_food items	
		tax = StateTaxes.salesTax(totalPrice);
		
		//returns the calculated tax
		return tax;       
	} //end nonFoodTax method      
    
	/**
	 * 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)
	{
		//local variables
		double tax;
		double totalPrice;
		 
		//initialize variables
		tax = 0.0;
		totalPrice = 0.0;
		 
		//calls total method to get the total for prepared_food items		
		totalPrice = total(prices, categories, PREPARED_FOOD);

		//calculates the sales tax for non_food items				
		tax = LocalTaxes.preparedFoodTax(totalPrice);
		
		//returns the calculated tax		
		return tax;       
	} //end preparedFoodTax method


	/**
    * 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)
	{
		//local variables
		double     total;
		
		//initialize variable
		total = 0.0;
		
		//for loop to get the total price for the particular category
		for (int i = 0; i < prices.length; i++)
		{
			//if condition to check for the specific category
			if (categoryToInclude == categories[i])
				total = total + prices[i];			
		}     
		
		//returns the calculated total
		return total;       
	} //end total method
    
    
	/**
	 * 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 condition to check for the valid category
		if (category == 0 || category == 1 || category == 2)
			if (!Character.isLetter(category))
				result = true;
		return result;       
	} //end isValid method  
} //end class
