/**
 * 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  Yang Yang
 * @version 1.0 Sep,14th,2008
 */
public class TaxCalculator
{
	//Hold the number which stand for non-food, food and prepared food
    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 tax = 0.0;//Hold all the food taxes and initialization
       
       /*
        * Call total method to get the total value of food,
        * and then call foodTax in StateTaxes class to calculate
        * he tax of all food.
        */
       tax = StateTaxes.foodTax(total(prices, categories, FOOD));
       
       return tax;//Return all the food 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)
    {
    	double tax = 0.0;//Hold all the non-food taxes and initialization
    	
    	/*
    	 * Call total method to get the total value of non-food,
    	 * and then call salesTax in StateTaxes class to calculate
    	 * the tax of all non-food.
    	 */
    	tax = StateTaxes.salesTax(total(prices, categories, NON_FOOD));
    	
        return tax;//Return all the food 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)
    {
    	double tax = 0.0;//Hold all the prepared food taxes and initialization
        
    	/*
    	 * Call total method to get the total value of prepared food,
    	 * and then call preparedFoodTax in LocalTaxes class to calculate
    	 * the tax of all prepared food.
    	 */
    	tax = LocalTaxes.preparedFoodTax(total(prices, categories, PREPARED_FOOD));
        
        return tax;//Return all the prepared food 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)
    {
       double     total;//Hold the total value of same-category stuffs
       
       total=0.0;//Initialization
       
       //The total value of same-category stuffs
       for(int i =0; i<prices.length;i++){
    	   if(categories[i] == categoryToInclude)
    		   total += prices[i];
       }//end for
    		  
       return total;//return the total value
       
    }//end total method
    
    
    /**
     * 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)
    {
       boolean     result;//Hold the determinant result
       
       //Determine if the category is valid or invalid
       if(category == 0 || category == 1 || category == 2)
    	   result = true;
       else{
    	   result = false;
    	   	 
       }//end else
       
       return result;//Return the result       
    
    }//End isValid method
    
}//End  TaxCalculator class
