public class Transaction extends Object implements 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(String transaction)
Initializes a new transaction by parsing a string of the form NAME DATE AMOUNT.
|
Transaction(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(Object x)
Is this transaction equal to x?
|
int |
hashCode()
Returns a hash code for this transaction.
|
static void |
main(String[] args)
Unit tests the transaction data type.
|
String |
toString()
Returns a string representation of the transaction.
|
Date |
when()
Returns the date of the transaction.
|
String |
who()
Returns the name of the customer involved in the transaction.
|
public Transaction(String who, Date when, double amount)
who - the person involved in the transactionwhen - the date of the transactionamount - the amount of the transactionIllegalArgumentException - if amount
is Double.NaN, Double.POSITIVE_INFINITY or
Double.NEGATIVE_INFINITYpublic Transaction(String transaction)
transaction - the string to parseIllegalArgumentException - if amount
is Double.NaN, Double.POSITIVE_INFINITY or
Double.NEGATIVE_INFINITYpublic String who()
public Date when()
public double amount()
public String toString()
public int compareTo(Transaction that)
compareTo in interface Comparable<Transaction>public boolean equals(Object x)
public int hashCode()
public static void main(String[] args)
Copyright © 2014. All Rights Reserved.