Java Cart .

Java Cart Item java

package cart;

//Item - a generic item
//author - Lawrence Truett - FluffyCat.com
//date - May 19, 2003 - San Diego, CA
public class Item {
    private long key;
    private ItemType itemType;
    //assumes simple system in one currecy, can be overridden
    private double price;
    private String description;
    private String smallGraphic;
    private String largeGraphic;
    private boolean hasInventory = false;
    private boolean onePerCart = false;
    private boolean isCartable = true;
    
    public Item(long keyIn, double priceIn, String descriptionIn,
    ItemType typeIn, String smallGraphicIn, String largeGraphicIn) {
        this.setKey(keyIn);
        this.setPrice(priceIn);
        this.setDescription(descriptionIn);
        this.setItemType(typeIn);
        this.setSmallGraphic(smallGraphicIn);
        this.setLargeGraphic(largeGraphicIn);
    }
    
    public Item(long keyIn, double priceIn, String descriptionIn,
    String typeIn, String smallGraphicIn, String largeGraphicIn) {
        this.setKey(keyIn);
        this.setPrice(priceIn);
        this.setDescription(descriptionIn);
        this.setItemType(typeIn);
        this.setSmallGraphic(smallGraphicIn);
        this.setLargeGraphic(largeGraphicIn);
    }
    
    public Item(long keyIn, double priceIn, String descriptionIn,
    char[] typeIn, String smallGraphicIn, String largeGraphicIn) {
        this.setKey(keyIn);
        this.setPrice(priceIn);
        this.setDescription(descriptionIn);
        this.setItemType(typeIn);
        this.setSmallGraphic(smallGraphicIn);
        this.setLargeGraphic(largeGraphicIn);
    }
    
    public long getKey() {return key;}
    private void setKey(long keyIn) {this.key = keyIn;}
    
    public ItemType getItemType() {return itemType;}
    void setItemType(ItemType itemTypeIn) {
        this.itemType = itemTypeIn;
    }
    void setItemType(String typeStringIn) {
        this.itemType = new ItemType(typeStringIn);
    }
    void setItemType(char[] typeCharsIn) {
        this.itemType = new ItemType(typeCharsIn);
    }
    
    public double getPrice() {return price;}
    void setPrice(double priceIn) {price = priceIn;}
    public double getPriceForQuantity(long quantityIn) {
    //can be overridden for special pricing deals
        return quantityIn * getPrice();
    }
    
    public String getDescription() {return description;}
    void setDescription(String descriptionIn) {
        description = descriptionIn;
    }
    
    public String getSmallGraphic() {return smallGraphic;}
    void setSmallGraphic(String smallGraphicIn) {
        smallGraphic = smallGraphicIn;
    }
    
    public String getLargeGraphic() {return largeGraphic;}
    void setLargeGraphic(String largeGraphicIn) {
        largeGraphic = largeGraphicIn;
    }
    
    public boolean getHasInventory() {return hasInventory;}
    void setHasInventory(boolean hasInventoryIn) {
        hasInventory = hasInventoryIn;
    }
    
    public boolean getOnePerCart() {return onePerCart;}
    void setOnePerCart(boolean onePerCartIn) {
        onePerCart = onePerCartIn;
    }
    
    public boolean getIsCartable() {return isCartable;}
    void setIsCartable(boolean isCartableIn) {
        isCartable = isCartableIn;
    }        
    
    public static String getItemClass() {return "Base Class Item";}
    
    public String toString() {
        return ("class - " + this.getItemClass() + 
                " key : " + this.getKey() + 
                " description: " + this.getDescription());}
}
To download source right-click here and "Save As...".
Comments
Sign in to be the first to comment on Java Cart Item java.