public class Transaction extends java.lang.Object implements java.lang.Comparable<Transaction>
For additional documentation, see Section 1.2 of Algorithms, 4th Edition, by Robert Sedgewick and Kevin Wayne.
| Modifier and Type | Class and Description |
|---|---|
static class |
Transaction.HowMuchOrder
Compares two transactions by amount.
|
static class |
Transaction.WhenOrder
Compares two transactions by date.
|
static class |
Transaction.WhoOrder
Compares two transactions by customer name.
|
| Constructor and Description |
|---|
Transaction(java.lang.String transaction)
Initializes a new transaction by parsing a string of the form NAME DATE AMOUNT.
|
Transaction(java.lang.String who,
Date when,
double amount)
Initializes a new transaction from the given arguments.
|
| Modifier and Type | Method and Description |
|---|---|
double |
amount()
Returns the amount of the transaction.
|
int |
compareTo(Transaction that)
Compares this transaction to that transaction.
|
boolean |
equals(java.lang.Object x)
Is this transaction equal to x?
|
int |
hashCode()
Returns a hash code for this transaction.
|
static void |
main(java.lang.String[] args)
Unit tests the transaction data type.
|
java.lang.String |
toString()
Returns a string representation of the transaction.
|
Date |
when()
Returns the date of the transaction.
|
java.lang.String |
who()
Returns the name of the customer involved in the transaction.
|
public Transaction(java.lang.String who,
Date when,
double amount)
who - the person involved in the transactionwhen - the date of the transactionamount - the amount of the transactionjava.lang.IllegalArgumentException - if amount
is Double.NaN, Double.POSITIVE_INFINITY or
Double.NEGATIVE_INFINITYpublic Transaction(java.lang.String transaction)
transaction - the string to parsejava.lang.IllegalArgumentException - if amount
is Double.NaN, Double.POSITIVE_INFINITY or
Double.NEGATIVE_INFINITYpublic java.lang.String who()
public Date when()
public double amount()
public java.lang.String toString()
toString in class java.lang.Objectpublic int compareTo(Transaction that)
compareTo in interface java.lang.Comparable<Transaction>public boolean equals(java.lang.Object x)
equals in class java.lang.Objectx - the other transactionpublic int hashCode()
hashCode in class java.lang.Objectpublic static void main(java.lang.String[] args)