public class ItemizedBill extends Object
Modifier and Type | Field and Description |
---|---|
private Date |
date
The date of purchase of this bill.
|
private List<Item> |
items
The list of items for this bill.
|
private int |
total
The total price of this bill.
|
Constructor and Description |
---|
ItemizedBill()
Initialize this bill so that it has the current date,
a total price of zero, and an empty list of items.
|
ItemizedBill(Date date,
List<Item> items)
Initialize this bill from a list of purchased items.
|
ItemizedBill(ItemizedBill other)
Initialize this bill by copying another bill.
|
Modifier and Type | Method and Description |
---|---|
void |
addItem(Item item)
Add an item to the list of items purchased for this bill.
|
Date |
getDate()
Returns a new date equal to the date of this bill.
|
List<Item> |
getItems()
Returns the list of items purchased for this bill.
|
Item |
getMostExpensiveItem()
Returns a copy of the most expensive item in this bill.
|
private static Item |
getMostExpensiveItem(List<Item> t)
Recursively searches the list
t for the most expensive
item. |
int |
getTotal()
Returns the total price of this bill.
|
void |
removeItem(Item item)
Removes the specified item from the list and updates the total
price of the bill.
|
private Date date
private int total
public ItemizedBill()
public ItemizedBill(Date date, List<Item> items)
date
- the date for this billitems
- a list of purchased itemspublic ItemizedBill(ItemizedBill other)
other
- the bill to copypublic List<Item> getItems()
public void addItem(Item item)
item
- add an item to the list of items purchased for this billpublic void removeItem(Item item)
item
- the item to remove from this billNoSuchElementException
- if this bill does not have the
specified itempublic Item getMostExpensiveItem()
IllegalArgumentException
- if this bill has no itemsprivate static Item getMostExpensiveItem(List<Item> t)
t
for the most expensive
item. Returns a copy of the most expensive item in t
.
If there is more than one item that has the highest price
then a copy of any one of those items will be returned.t
- a non-empty list of itemspublic Date getDate()
public int getTotal()