From f0ef08edbcf2ab7258ab9de7e7ef1b4d7ed1719c Mon Sep 17 00:00:00 2001 From: HSoreide <sofie.scisly@gmail.com> Date: Sun, 5 Mar 2023 10:15:14 +0100 Subject: [PATCH] Add JavaDoc to Income and Expense classes --- .../no/ntnu/idatt1002/demo/data/Expense.java | 29 ++++++++++++++----- .../idatt1002/demo/data/ExpenseCategory.java | 1 + .../no/ntnu/idatt1002/demo/data/Income.java | 29 +++++++++++++++++-- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Expense.java b/src/main/java/no/ntnu/idatt1002/demo/data/Expense.java index 72a0f5be..06d8d716 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Expense.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Expense.java @@ -1,10 +1,17 @@ package no.ntnu.idatt1002.demo.data; public class Expense extends Item{ - private ExpenseCategory category; - + /** + * This constructor uses the super constructor to set the fields for 'amount' and 'recurring' and then sets the + * category. A IllegalArgumentException from this constructor if the category is left blank. The description + * field is left to the default blank string. + * + * @param amount The amount of the current Expense object as a double. + * @param recurring True if the current Expense repeats at regular intervals. + * @param category The category to which the Expense belongs to, provided as a value of ExpenseCategory. + */ public Expense(double amount, boolean recurring, ExpenseCategory category) { super(amount, recurring); @@ -14,6 +21,14 @@ public class Expense extends Item{ this.category = category; } + /** + * This constructor uses the super constructor to set the fields for 'amount', 'description' and 'recurring' + * and then sets the category. A IllegalArgumentException from this constructor if the category is left blank. + * @param description A description of the Expense as a String. + * @param amount The amount of the current Expense object as a double. + * @param recurring True if the current income repeats at regular intervals. + * @param category The category to which the Expense belongs to, provided as a value of ExpenseCategory + */ public Expense(String description, double amount, boolean recurring, ExpenseCategory category) { super(description, amount, recurring); if(category == null) { @@ -24,20 +39,20 @@ public class Expense extends Item{ } /** - * The method returns the category to which the Item belongs as a value of the Category enum class. - * @return The category the Item belongs to as a value of the Category enum class. + * The method returns the category to which the Expense belongs as a value of the ExpenseCategory enum class. + * @return The category the Expense belongs to as a value of the ExpenseCategory enum class. */ public ExpenseCategory getCategory() { return category; } /** - * The method sets the category of an item to a value of the Category enum class. - * @param expenseCategory The category to which the Item should belong. + * The method sets the category of an expense to a value of the ExpenseCategory enum class. + * @param expenseCategory The category to which the expense belongs as a value of the ExpenseCategory enum. */ public void setCategory(ExpenseCategory expenseCategory) { if(expenseCategory == null) { - throw new IllegalArgumentException("The category must be valid."); + throw new IllegalArgumentException("The income must belong to a category."); } this.category = expenseCategory; } diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/ExpenseCategory.java b/src/main/java/no/ntnu/idatt1002/demo/data/ExpenseCategory.java index 0d40833f..0460a400 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/ExpenseCategory.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/ExpenseCategory.java @@ -4,6 +4,7 @@ public enum ExpenseCategory { FOOD, CLOTHES, + BOOKS, OTHER, } diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Income.java b/src/main/java/no/ntnu/idatt1002/demo/data/Income.java index a3ba7ba2..20bab51c 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Income.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Income.java @@ -1,9 +1,24 @@ package no.ntnu.idatt1002.demo.data; +/** + * The Income class inherits from the Item class. The Item class additionally has a private field for an + * enum value of IncomeCategory. + * + * @author Hanne-Sofie + */ public class Income extends Item{ private IncomeCategory category; + /** + * This constructor uses the super constructor to set the fields for 'amount' and 'recurring' and then sets the + * category. A IllegalArgumentException from this constructor if the category is left blank. The description + * field is left to the default blank string. + * + * @param amount The amount of the current income object as a double. + * @param recurring True if the current income repeats at regular intervals. + * @param category The category to which the Income belongs to, provided as a value of IncomeCategory. + */ public Income(double amount, boolean recurring, IncomeCategory category) { super(amount, recurring); @@ -13,6 +28,14 @@ public class Income extends Item{ this.category = category; } + /** + * This constructor uses the super constructor to set the fields for 'amount', 'description' and 'recurring' + * and then sets the category. A IllegalArgumentException from this constructor if the category is left blank. + * @param description A description of the income as a String. + * @param amount The amount of the current income object as a double. + * @param recurring True if the current income repeats at regular intervals. + * @param category The category to which the income belongs to, provided as a value of IncomeCategory + */ public Income(String description, double amount, boolean recurring, IncomeCategory category) { super(description, amount, recurring); if(category == null) { @@ -23,8 +46,8 @@ public class Income extends Item{ } /** - * The method returns the category to which the Item belongs as a value of the Category enum class. - * @return The category the Item belongs to as a value of the Category enum class. + * The method returns the category to which the Income belongs as a value of the IncomeCategory enum. + * @return The category to which the Income belongs to as a value of the IncomeCategory enum. */ public IncomeCategory getCategory() { return category; @@ -32,7 +55,7 @@ public class Income extends Item{ /** * The method sets the category of an item to a value of the Category enum class. - * @param category The category to which the Item should belong. + * @param category The category to which the Income belongs to as a value of the IncomeCategory enum. */ public void setCategory(IncomeCategory category) { if(category == null) { -- GitLab