Package no.ntnu.idatt1002.spendwise.data
Class Transaction
java.lang.Object
no.ntnu.idatt1002.spendwise.data.Transaction
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 Summary
ConstructorDescriptionTransaction
(String name, String notes, String date, double amount) Constructor for a transaction. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract String
Returns the amount of the transaction as a String.double
Returns the amount of the transaction.Returns the amount of the transaction as a String.Returns the category of the transaction.getDate()
Returns the date of the transaction.getName()
Returns the name of the transaction.getNotes()
Returns the notes of the transaction.boolean
isWithinTimeFrame
(LocalDate fromDate, LocalDate toDate) Checks if the transaction is within the given time frame.void
setCategory
(String category) Sets the category of the transaction.
-
Constructor Details
-
Transaction
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
Returns the name of the transaction.- Returns:
- The name of the transaction as a String.
-
getNotes
Returns the notes of the transaction.- Returns:
- The notes of the transaction as a 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
Returns the amount of the transaction as a String. Used for formatting in TableView.- Returns:
- The amount of the transaction as a String.
-
getCategory
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
Sets the category of the transaction. Guarantees immutability safety.- Parameters:
category
- The category to be set.
-
amountToString
Returns the amount of the transaction as a String. Used for formatting.- Returns:
- The amount of the transaction as a String.
-
isWithinTimeFrame
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.
-