/**
 * PA1
 * 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  Daniel Heck
 * @version 1.1 9/6/08
 */
public class TaxCalculator
{
	//Constants representing different categories
    public static int NON_FOOD        = 0; //Not food
    public static int FOOD            = 1; //Unprepared food
    public static int PREPARED_FOOD   = 2; //Prepared food
    

    /**
     * Calculate the tax on the (non-prepared) food items
     *
     * @param prices      prices The prices of all items purchases
     * @param categories  categories The corresponding categories of all items purchases
     * @return            tax	the finalized tax after all processes
     */
    public static double foodTax(double[] prices, int[] categories)
    {
       double tax;	//declare local double variable tax for returning final tax
       double total;//decalre local double variable total
       
       //Set total by callign the total method sending it the prices, categories, and current category
		total = total(prices, categories, FOOD);
		//Set taxes = to the State food tax by sending it the double total
		tax = StateTaxes.foodTax(total);

       return tax;  //return the finalized 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;
       double	total;
       
       //Set total by callign the total method sending it the prices, categories, and current category
		total = total(prices, categories, NON_FOOD);
		//Set taxes = to the State sales tax by sending it the double total
		tax = StateTaxes.salesTax(total);

       return tax;  //return the finalized 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;
       double total;
     
       //Set total by callign the total method sending it the prices, categories, and current category
       total = total(prices, categories, PREPARED_FOOD);
       //Set taxes = to the Local prepared food tax by sending it the double total
       tax   = LocalTaxes.preparedFoodTax(total);

       return tax;  //return the finalized 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;	//declare local variable total for arthimetic
       
       //initialize total to avoid null pointer
       total = 0;
          
        //Loop while still getting prices in the array  
     	for(int ii = 0; ii < prices.length; ii++)
     	{
     		//if the categoriy is correct
     		if(categoryToInclude == categories[ii])
     			total = total + prices[ii]; //Set total = to the prices + the current total	
     	}//end for loop
       
       return total;	//Return the finalized total  
    }//end 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)
    {
       boolean     result;	//declare local varible result 
       
       //if the category is less than 0 or greater than 2 it is invalid
       if(category < 0 || category > 2)
       	result = false; //adjust boolean to false for bad input
       else
       	result = true;  //adjust boolean to true for correct input
       
       return result; //Return boolean result containing whether or not good cat
    }//end isValid
}//end Class
