Package dsa

Class Transaction

    • Constructor Detail

      • Transaction

        public Transaction​(String name,
                           Date date,
                           double amount)
        Constructs a transaction from a name, date, and amount.
        Parameters:
        name - name of the person involved in this transaction.
        date - date of this transaction.
        amount - amount of this transaction.
      • Transaction

        public Transaction​(String s)
        Constructs a transaction from a string s of the form "name date amount".
        Parameters:
        s - the string.
    • Method Detail

      • name

        public String name()
        Returns the name of the person involved in this transaction.
        Returns:
        the name of the person involved in this transaction.
      • date

        public Date date()
        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.
      • hashCode

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

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

        public int compareTo​(Transaction other)
        Returns a comparison of this transaction with other, by amount.
        Specified by:
        compareTo in interface Comparable<Transaction>
        Parameters:
        other - the other transaction.
        Returns:
        a comparison of this transaction with other, by amount.
      • nameOrder

        public static Comparator<Transaction> nameOrder()
        Returns a comparator for comparing two transactions by name.
        Returns:
        a comparator for comparing two transactions by name.
      • dateOrder

        public static Comparator<Transaction> dateOrder()
        Returns a comparator for comparing two transactions by date.
        Returns:
        a comparator for comparing two transactions by date.
      • main

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