
/**
 * TaxRule.java
 *
 *
 * Created: Tue Nov 19 19:56:56 2002
 *
 * @author <a href="mailto:bina@cse.buffalo.edu "</a>
 * @version
 */

public abstract class TaxRule {
   abstract Object computeTax(Object input);
}// TaxRule

/**
 * USTaxRule.java
 *
 *
 * Created: Tue Nov 19 20:02:20 2002
 *
 * @author <a href="mailto:bina@cse.buffalo.edu "</a>
 * @version
 */

public class USTaxRule extends TaxRule{
   public USTaxRule (){
      
   }
   public Object computeTax(Object inp)
   {
      double salesTax = 0.08;

      double total = ((Double)inp).doubleValue();
      total = total + total*salesTax;
      return (new Double(total));
   }
      
}// USTaxRule

/**
 * CanadaTaxRuleNew.java
 *
 *
 * Created: Tue Nov 19 22:48:50 2002
 *
 * @author <a href="mailto:bina@cse.buffalo.edu "</a>
 * @version
 */

public class CanadaTaxRuleNew extends TaxRule{
   public CanadaTaxRuleNew (){
      
   }
   
      Object computeTax(Object inp)
   {
      double gst = 0.07;
      double pst = 0.08;
      double total = ((Double)inp).doubleValue();
      double beforeTax = total;
      total = total + total*gst;
      total = total + total*pst;
      return (new PriceTax(total, total-beforeTax));
   }

}// CanadaTaxRuleNew

/**
 * Checkout2.java
 *
 *
 * Created: Tue Nov 19 22:28:37 2002
 *
 * @author <a href="mailto:bina@cse.buffalo.edu "</a>
 * @version
 */
import java.text.*;
import java.util.*;
public class Checkout2 {
  public static void main (String[] args) {
      double price1= 4.5, price2= 7.8, price3= 6.5;
      double total;
      double tax;

      NumberFormat nf = 
       NumberFormat.getCurrencyInstance(Locale.US);
    
      TaxRule t = new CanadaTaxRule();// can be replaced by CanadaTaxRule

      
      total = price1 + price2 + price3;

      System.out.println("The total price before tax is: " + nf.format(total));

      total = ((Double)t.computeTax(new Double(total))).doubleValue();

      System.out.println("The total price after tax is: " + nf.format(total));
      
   } // end of main ()
   
}// Checkout2

/**
 * Checkout3.java
 *
 *
 * Created: Tue Nov 19 22:41:23 2002
 *
 * @author <a href="mailto:bina@cse.buffalo.edu "</a>
 * @version
 */
import java.text.*;
import java.util.Locale;

public class Checkout3 {
public static void main (String[] args) {
      double price1= 4.5, price2= 7.8, price3= 6.5;
      double total;
      double tax;

      NumberFormat nf = 
       NumberFormat.getCurrencyInstance(Locale.US);
    
      TaxRule t = new CanadaTaxRuleNew();// can be replaced by CanadaTaxRule

      
      total = price1 + price2 + price3;

      System.out.println("The total price before tax is: " + nf.format(total));

      PriceTax pt = (PriceTax)t.computeTax(new Double(total));

      System.out.println("The total  tax is: " + 
			 nf.format(pt.getTax()));
      System.out.println("The total price after tax is: " + 
			 nf.format(pt.getTotal()));
      
   } // end of main ()
   
}// Checkout3
