01: /**
02: * Copyright (c) 2005 Red Hat, Inc. All rights reserved.
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17: * USA
18: *
19: * Component of: Red Hat Application Server
20: *
21: * Initial Developers: Gregory Lapouchnian
22: * Patrick Smith
23: * --------------------------------------------------------------------------
24: * $Id: OrderItem.java 7027 2005-07-08 14:00:45Z glapouch $
25: * --------------------------------------------------------------------------
26: */package olstore.client;
27:
28: import java.text.DecimalFormat;
29:
30: /**
31: * Represents an order for an item.
32: */
33: public class OrderItem extends Item {
34:
35: /** The quantity being ordered for this item. */
36: private int quantity;
37:
38: /**
39: * Create a new order for a given item.
40: * @param item the item being ordered
41: */
42: public OrderItem(Item item) {
43: super (item.getTitle(), item.getDescription(), item.getPrice(),
44: item.getCategory(), item.getId(), item.getImage());
45:
46: quantity = 1;
47: }
48:
49: /**
50: * Get the quantity being ordered.
51: * @return Returns the quantity.
52: */
53: public int getQuantity() {
54: return quantity;
55: }
56:
57: /**
58: * Set the quantity for this item.
59: * @param quantity The quantity to set.
60: */
61: public void setQuantity(int quantity) {
62: this .quantity = quantity;
63: }
64:
65: /**
66: * @see java.lang.Object#equals(java.lang.Object)
67: */
68: public boolean equals(Object other) {
69: return getId().equals(((OrderItem) other).getId());
70: }
71:
72: /**
73: * Get the total for this order.
74: * @return the total price for this order
75: */
76: public double getTotal() {
77: DecimalFormat formatter = new DecimalFormat("#.00");
78: return (double) quantity
79: * Double.valueOf(super.getPrice()).doubleValue();
80: }
81: }
|