FileDocCategorySizeDatePackage
Cashier.javaAPI DocExample1905Tue Dec 12 18:59:38 GMT 2000cart

Cashier

public class Cashier extends Object

Fields Summary
private static final double
SalesTaxRate
ShoppingCart
cart
Constructors Summary
public Cashier(ShoppingCart cart)


       
        this.cart = cart;
    
Methods Summary
public static java.lang.Stringformat(double d)

        NumberFormat nf = NumberFormat.getCurrencyInstance();
        return nf.format(d);
    
public doublegetAmount()

        double amount = 0.0;

        for(Enumeration e = cart.getItems(); e.hasMoreElements(); ) {
            ShoppingCartItem item = (ShoppingCartItem) e.nextElement();
            BookDetails bookDetails = (BookDetails) item.getItem();

            amount += item.getQuantity() * bookDetails.getPrice();
        }
        return roundOff(amount);
    
public doublegetTax()

        return roundOff(getAmount() * SalesTaxRate);
    
public doublegetTotal()

        return roundOff(getAmount() + getTax());
    
private doubleroundOff(double x)

        long val = Math.round(x*100); // cents
        return val/100.0;