KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > olstore > client > OrderItem


1 /**
2  * Copyright (c) 2005 Red Hat, Inc. All rights reserved.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * 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,v 1.2 2005/07/08 14:00:45 glapouch Exp $
25  * --------------------------------------------------------------------------
26  */

27 package olstore.client;
28
29 import java.text.DecimalFormat;
30
31 /**
32  * Represents an order for an item.
33  */

34 public class OrderItem extends Item {
35
36     /** The quantity being ordered for this item. */
37     private int quantity;
38
39     /**
40      * Create a new order for a given item.
41      * @param item the item being ordered
42      */

43     public OrderItem(Item item) {
44         super(item.getTitle(), item.getDescription(), item.getPrice(), item
45                 .getCategory(), item.getId(), item.getImage());
46
47         quantity = 1;
48     }
49
50     /**
51      * Get the quantity being ordered.
52      * @return Returns the quantity.
53      */

54     public int getQuantity() {
55         return quantity;
56     }
57
58     /**
59      * Set the quantity for this item.
60      * @param quantity The quantity to set.
61      */

62     public void setQuantity(int quantity) {
63         this.quantity = quantity;
64     }
65
66     /**
67      * @see java.lang.Object#equals(java.lang.Object)
68      */

69     public boolean equals(Object other) {
70         return getId().equals(((OrderItem) other).getId());
71     }
72
73     /**
74      * Get the total for this order.
75      * @return the total price for this order
76      */

77     public double getTotal() {
78         DecimalFormat formatter = new DecimalFormat("#.00");
79         return (double) quantity
80                 * Double.valueOf(super.getPrice()).doubleValue();
81     }
82 }
83
Popular Tags