
/**
 * 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  Jeremy Halterman
 * @version 1.1
 * @date 9-16-08
 */

/*public class called TaxCalculator*/
public class TaxCalculatorZ
{
	//publicly available int values for any class in package
	//predefined for categorizing fields
    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 tax        The tax
     */
    public static double foodTax(double[] prices, int[] categories)
    {
       double tax; //accumulator
       tax = 0.0;  //initialized to 0
       //locally defined variable for holding each loops' value
       double temp;
       temp = 0;
       
       /*a loop that scans through each array value passed to it*/
       for (int i = 0; i<prices.length; i++)
       {
    	   //tests arrays and only accepts those that match respective category
    	   if(categories[i] == 1)
    	   {
    		  //sum up the prices in the array for the category
    		  //then use the foodTax method to get tax on that total...
    		  temp += prices[i];
    	   }//end if
    	   
       }//end for loop
       
    	 /*calls foodTax method to evaluate the actual taxes for total items*/
  		 tax = StateTaxesZ.foodTax(temp);
 
        /*returns total of this categories taxes--when called by
         *CalculatorDriver and TaxOnomy*/
       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 tax        The tax
     */
    public static double nonfoodTax(double[] prices, int[] categories)
    {
       double tax;//accumulator
       tax = 0.0; //initialized variable
       //locally defined variable for holding each loops' value
       double temp;
       temp = 0.0;
       
       /*a loop that scans through each array value passed to it*/
       for (int i = 0; i<prices.length; i++)
       {
    	   //tests arrays and only accepts those that match respective category
    	   if(categories[i] == 0)
    	   {
             //sum up the prices in the array for the category
     		 //then use the salesTax method to get tax on that total...
    		 temp += prices[i];
 
    	   }//end if
       }//end for loop
       
       /*passes values to salesTax method and stores result in 'tax'*/
		 tax =StateTaxesZ.salesTax(temp);
		 
       /*returns total of this categories taxes--when called by
        *CalculatorDriver and TaxOnomy*/
       return tax;       
    }//end SalesTax 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 tax        The tax
     */
    public static double preparedfoodTax(double[] prices, int[] categories)
    {
       double tax;//accumulator
       tax = 0.0; //initializes variable
       //locally defined variable for holding each loops' value
       double temp;
       temp = 0.0;
       
       /*a loop that scans through each array value passed to it*/
       for (int i = 0; i<prices.length; i++)
       {
            //tests arrays and only accepts those that match respective category
    	   if(categories[i] == 2)
    	   {
    		   
             //sum up the prices in the array for the category
       		 //then use the preparedFoodTax method to get tax on that total...
      		 temp += prices[i];
    		 
    	   }//end if
       }//end for loop
       
       /*passes values to preparedFoodTax method and 
		  *stores result in 'tax'*/
		 tax = LocalTaxesZ.preparedFoodTax(temp);
       
       /*returns total of this categories taxes--when called by
        *CalculatorDriver and TaxOnomy*/
       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 total          The total value of items in the given category
     */
    public static double total(double[] prices, int[] categories, 
                                int categoryToInclude)
    {
       double     total;//accumulator category's taxes
       total = 0.00;    //initialized variable
       double temp;     //another variable for holding looping results
       temp = 0.00;     //initialized variable
       double gatherTax;
       gatherTax = 0.0;
       
       /*a loop that scans through each array value passed to it*/
       for(int i=0; i<prices.length;i++)
       {
           //tests arrays and only accepts those that match respective category
    	   //specifically uses the extra parameter variable for comparing to a
    	   //loop that reads each array values since these are totally random
    	   //based on user's input
    	   if(categoryToInclude == categories[i])
    	   {
    	   /*passes values and 
      		*stores results in 'temp'*/
    	   temp += prices[i];
    	   
    	   
    	   }//end if
           
       }//end for loop		
    	   
    	   
    	        /*used to compare each category chosen to
    	   		 *every other category, for purposes of using proper tax field*/
    	   		if(categoryToInclude == 0)
    	   		{
    	   			gatherTax = StateTaxesZ.salesTax(temp);
    	   		}
    	   		else if(categoryToInclude == 1)
    	   		{
    	   			gatherTax = StateTaxesZ.foodTax(temp);
    	   		}
    	   		else
    	   		{
    	   			gatherTax = LocalTaxesZ.preparedFoodTax(temp);
    	   		}
    	  
        //sums up total cost of any category needed along with proper tax
    	total = gatherTax + temp;
    	   		
        //returns total of each category needed, only without taxes included
       	return total;
       
    }//end total method
    
    
    /**
     * Determin if the given category is valid
     *
     * @param category   The category of interest
     * @return result          true if the category is valid; false otherwise
     */
    public static boolean isValid(int category)
    {
       //boolean for the return
       boolean     result;
       result = false;
       	   //a simple parameter test - is it between 0 and 2?
       	   if((category>=0) && (category<=2))
       	   {
       		 //boolean changed if block is satisfied  
       		 result = true;  
       	   }//end if
       
       		//return boolean result
       return result;       
    }//end isValid method
    
}//end TaxCalculator class
