package murach.business;


import java.text.NumberFormat;

public class LineItem {

    private Product product;
    private int quantity;
    private double total;

    public LineItem() {
        this.product = new Product();
        this.quantity = 0;
        this.total = 0;
    }

    public LineItem(Product product, int quantity) {
        this.product = product;
        this.quantity = quantity;
        this.calculateTotal();
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public Product getProduct() {
        return product;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public int getQuantity() {
        return quantity;
    }

    public String getQuantityFormatted() {
        NumberFormat number = NumberFormat.getNumberInstance();
        return number.format(quantity);
    }
    
    public void setTotal(double total) {
        this.total = total;
    }

    public double getTotal() {
        return total;
    }

    public void calculateTotal() {
        total = quantity * product.getPrice();
    }

    public String getTotalFormatted() {
        NumberFormat currency = NumberFormat.getCurrencyInstance();
        return currency.format(total);
    }
}
