/**
 * A utility class that can be used to calculate state taxes.
 *
 * In this case, there is a sales tax on all items but
 * (non-prepared) food has a special exemption.
 *
 *
 * This work complies with the JMU Honor Code.
 *
 * @author  Jimmy Tessitore
 * @version 1.0  September 9, 2008
 */
    public class StateTaxes
   {
      private static double FOOD_EXEMPTION_RATE = 0.02;
      private static double SALES_TAX_RATE      = 0.05;
    
   
    /**
     * Calculate the exemption on (non-prepared) food
     * 2% of the total value if the value is positive
	  *
     * @param value   The value of the (non-prepared) food
     * @return        The exemption (in dollars)
     */
       public static double foodExemption(double value)
      {
       //Declaration
         double   exemption;
       
       //Loop to calculate only if the purhcase is greater than or equal to 0
         if(value >= 0)
         {
         //Calculates food exemption
            exemption = value * FOOD_EXEMPTION_RATE;
         }
         
         //If it is less than 0 it becomes 0
         else
         {
            exemption = 0.0;
         }
       
       //Return food exemption
         return exemption;       
      }
   
   
    /**
     * Calculate the tax on (non-prepared) food.
     *
     * The food tax is the sales tax less the food exemption.
     *
     * @param value   The value of the (non-prepared) food
     * @return        The tax (in dollars)
     */
       public static double foodTax(double value)
      {
       //Declarations
         double   tax;
      	double sales;
			double exemption;
			
			//Instantiations
			//Makes local variables hold the values the two methods calculate
			sales = salesTax(value);
			exemption = foodExemption(value);
			
       //Calculates food tax(sales tax minus food tax)
         tax = sales - exemption;
      	
      	//If the exemption is greater than the sales tax, the total tax becoms 0
         if(tax <= 0)
            tax = 0;
        
       //Return food tax 
         return tax;       
      }
    
   
   
    /**
     * Calculate the sales tax.
     * 5% of the total value purchased if total value is $0.20 or more
	  * If total value is less than $0.20, sales tax becomes 0.0
	  * 
     * @param value   The value of the items
     * @return        The tax (in dollars)
     */
       public static double salesTax(double value)
      {
       //Declaration
         double    tax;		 
       
       //Loop to calculate sales tax if the purchase is 
       //greater than or equal to 0 and is greater than 20 cents
         if(value >= .2)
         {
         //Calculates sales tax
            tax = value * SALES_TAX_RATE;       
         }
         
         //Loop sets tax to 0 if purchase is less than 20 cents or negative
         else
         {
            tax = 0.0;
         }
      
       //Return sales tax
         return tax;       
      }
    
   }//end StateTaxes
