public final class Item extends Object implements Comparable<Item>
| Constructor and Description |
|---|
Item(Item other)
Initialize an item by copying another item.
|
Item(String description,
int price)
Initialize an item by setting its description and price.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Item other)
Compares two items numerically by their price.
|
boolean |
equals(Object obj)
Compares two items for equality.
|
String |
getDescription()
Get the item description.
|
int |
getPrice()
Get the item price.
|
int |
hashCode()
Returns the hash code for this item.
|
void |
setDesc(String desc)
Set the item description to the specified description.
|
void |
setPrice(int price)
Set the item price to the specified price.
|
String |
toString()
Returns a string representation of this item.
|
public Item(String description, int price)
description - the item descriptionprice - the item priceIllegalArgumentException - if the item price is less than zeropublic Item(Item other)
other - the item to copypublic String getDescription()
public void setDesc(String desc)
description - the item description to setpublic int getPrice()
public final void setPrice(int price)
price - the item price to setIllegalArgumentException - if the argument is less than zeropublic int hashCode()
hashCode in class ObjectObject.hashCode()public boolean equals(Object obj)
equals in class Objectobj - the object to compare this item againstObject.equals(java.lang.Object)public String toString()
toString in class ObjectObject.toString()public int compareTo(Item other)
The value 0 is returned if both items have the same price.
A negative value is returned if this item has a price less than the other item, or if both items have the same price and this item has a description that is lexicographically less than the other item description.
A positive value is returned if this item has a price greater than the other item, or if both items have the same price and this item has a description that is lexicographically greater than the other item description.
compareTo in interface Comparable<Item>other - the item to be compared