orderprocessing
Class OrderItem

java.lang.Object
  extended byorderprocessing.OrderItem
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class OrderItem
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

This class contains information about a single item on a customer order. Note that this class implements the Immutable Object design pattern.

These are used for both orders and invoices.

See Also:
Serialized Form

Constructor Summary
OrderItem(int quantity, long itemNumber, double unitPrice, java.lang.String description)
          Create an order item for a given quantity of a certain item
 
Method Summary
 java.lang.Object clone()
           
 java.lang.String description()
          Retrieve the description of the item in this order item
 void display()
          Display this order item on standard out
 void displayExtended()
          Display the order item along with its extended price on standard out.
 boolean equals(java.lang.Object o)
           
 double extendedPrice()
          Retrieve the extended price (unit price times quantity) for this order item
static OrderItem genOrderItem(java.lang.String orderItem, java.lang.String sep)
          Generate a new order item from a correctly formatted string.
 int hashCode()
           
 long itemNumber()
          Retrieve the item number for this order item
 int quantity()
          Retrieve the quantity for this order item
 java.lang.String toString()
           
 double unitPrice()
          Retrieve the unit price of this item
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OrderItem

public OrderItem(int quantity,
                 long itemNumber,
                 double unitPrice,
                 java.lang.String description)
Create an order item for a given quantity of a certain item

Parameters:
quantity - The quantity ordered.
itemNumber - The item desired.
unitPrice - The price per unit for this item.
description - - Item description
Method Detail

quantity

public int quantity()
Retrieve the quantity for this order item

Returns:
the quantity ordered

itemNumber

public long itemNumber()
Retrieve the item number for this order item

Returns:
the item number TODO should probably be a code

unitPrice

public double unitPrice()
Retrieve the unit price of this item

Returns:
the price TODO should we worry about precision?

extendedPrice

public double extendedPrice()
Retrieve the extended price (unit price times quantity) for this order item

Returns:
the extended price

description

public java.lang.String description()
Retrieve the description of the item in this order item

Returns:
the description of the item

equals

public boolean equals(java.lang.Object o)

hashCode

public int hashCode()

display

public void display()
Display this order item on standard out


displayExtended

public void displayExtended()
Display the order item along with its extended price on standard out.


clone

public java.lang.Object clone()

toString

public java.lang.String toString()

genOrderItem

public static OrderItem genOrderItem(java.lang.String orderItem,
                                     java.lang.String sep)
Generate a new order item from a correctly formatted string. Caller is responsible for the correctness.

Parameters:
orderItem - the string describing the order item
sep - the separator character(s) used in the description string
Returns:
a new Order item