Documentation of 'edu.princeton.cs.algs4.Transaction' Java class
Transaction
edu.princeton.cs.algs4

Class Transaction

  • All Implemented Interfaces:
    java.lang.Comparable<Transaction>


    public class Transaction
    extends java.lang.Object
    implements java.lang.Comparable<Transaction>
    The Transaction class is an immutable data type to encapsulate a commercial transaction with a customer name, date, and amount.

    For additional documentation, see Section 1.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

    • Constructor Summary

      Constructors 
      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.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      double amount()
      Returns the amount of this transaction.
      int compareTo(Transaction that)
      Compares two transactions by amount.
      boolean equals(java.lang.Object other)
      Compares this transaction to the specified object.
      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 this transaction.
      Date when()
      Returns the date of this transaction.
      java.lang.String who()
      Returns the name of the customer involved in this transaction.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Transaction

        public Transaction(java.lang.String who,
                           Date when,
                           double amount)
        Initializes a new transaction from the given arguments.
        Parameters:
        who - the person involved in this transaction
        when - the date of this transaction
        amount - the amount of this transaction
        Throws:
        java.lang.IllegalArgumentException - if amount is Double.NaN, Double.POSITIVE_INFINITY, or Double.NEGATIVE_INFINITY
      • Transaction

        public Transaction(java.lang.String transaction)
        Initializes a new transaction by parsing a string of the form NAME DATE AMOUNT.
        Parameters:
        transaction - the string to parse
        Throws:
        java.lang.IllegalArgumentException - if amount is Double.NaN, Double.POSITIVE_INFINITY, or Double.NEGATIVE_INFINITY
    • Method Detail

      • who

        public java.lang.String who()
        Returns the name of the customer involved in this transaction.
        Returns:
        the name of the customer involved in this transaction
      • when

        public Date when()
        Returns the date of this transaction.
        Returns:
        the date of this transaction
      • amount

        public double amount()
        Returns the amount of this transaction.
        Returns:
        the amount of this transaction
      • toString

        public java.lang.String toString()
        Returns a string representation of this transaction.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of this transaction
      • compareTo

        public int compareTo(Transaction that)
        Compares two transactions by amount.
        Specified by:
        compareTo in interface java.lang.Comparable<Transaction>
        Parameters:
        that - the other transaction
        Returns:
        { a negative integer, zero, a positive integer}, depending on whether the amount of this transaction is { less than, equal to, or greater than } the amount of that transaction
      • equals

        public boolean equals(java.lang.Object other)
        Compares this transaction to the specified object.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        other - the other transaction
        Returns:
        true if this transaction is equal to other; false otherwise
      • hashCode

        public int hashCode()
        Returns a hash code for this transaction.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        a hash code for this transaction
      • main

        public static void main(java.lang.String[] args)
        Unit tests the Transaction data type.
        Parameters:
        args - the command-line arguments

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.