Class Transaction

java.lang.Object
no.ntnu.idatt1002.spendwise.data.Transaction
Direct Known Subclasses:
Expense, Income

public abstract class Transaction extends Object
Abstract class that Expense/Income inherits from. All instances derived from this class are immutable. The class uses SimpleStringProperty to format properly in TableViews
  • Constructor Details

    • Transaction

      public Transaction(String name, String notes, String date, double amount)
      Constructor for a transaction.
      Parameters:
      name - The name given to the transaction.
      notes - The notes given to the transaction, may be empty.
      date - The date given to the transactions as a String. ISO 8601 format.
      amount - The amount of the transactions as a double. Does not specify a currency
  • Method Details

    • getName

      public String getName()
      Returns the name of the transaction.
      Returns:
      The name of the transaction as a String.
    • getNotes

      public String getNotes()
      Returns the notes of the transaction.
      Returns:
      The notes of the transaction as a String.
    • getDate

      public String getDate()
      Returns the date of the transaction.
      Returns:
      The date of the transaction as a String in ISO 8601 format.
    • getAmount

      public double getAmount()
      Returns the amount of the transaction.
      Returns:
      The amount of the transaction as a double.
    • getAmountString

      public String getAmountString()
      Returns the amount of the transaction as a String. Used for formatting in TableView.
      Returns:
      The amount of the transaction as a String.
    • getCategory

      public String getCategory() throws ConformityException
      Returns the category of the transaction.
      Returns:
      The category of the transaction as a String.
      Throws:
      ConformityException - If the category has not been set yet.
    • setCategory

      public void setCategory(String category)
      Sets the category of the transaction. Guarantees immutability safety.
      Parameters:
      category - The category to be set.
    • amountToString

      protected abstract String amountToString()
      Returns the amount of the transaction as a String. Used for formatting.
      Returns:
      The amount of the transaction as a String.
    • isWithinTimeFrame

      public boolean isWithinTimeFrame(LocalDate fromDate, LocalDate toDate)
      Checks if the transaction is within the given time frame.
      Parameters:
      fromDate - The start date of the time frame.
      toDate - The end date of the time frame.
      Returns:
      True if the transaction is within the time frame, false otherwise.