From d02e6617910a01d774fba1527a9bbea37c8a542c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adele=20Iren=20Westrum=20Kj=C3=B8lstad?= <aikjolst@stud.ntnu.no> Date: Wed, 22 Mar 2023 11:24:25 +0100 Subject: [PATCH] Adds javadoc to BudgetItem and GeneralBudget --- .../demo/data/Budget/BudgetItem.java | 31 ++++++++++++++++++ .../demo/data/Budget/GeneralBudget.java | 32 ++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/BudgetItem.java b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/BudgetItem.java index 976a772a..e3fa2d52 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/BudgetItem.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/BudgetItem.java @@ -2,25 +2,56 @@ package no.ntnu.idatt1002.demo.data.Budget; import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory; +/** + * This class represents a budgetItem + * + * @author Adele + */ public class BudgetItem { private double budgetAmount; private ExpenseCategory category; private String description; + /** + * The constructor of a new Budgetitem. + * + * @param budgetAmount The amount of budget as a double + * @param description A description of the budget as a String + * @param category A category from ExpenseCategory + * + */ public BudgetItem(double budgetAmount, String description, ExpenseCategory category){ this.budgetAmount = budgetAmount; this.description = description; this.category = category; } + /** + * This method gets the BudgetAmount. + * + * @return the budgetAmount as a double + * + */ public double getBudgetAmount() { return budgetAmount; } + /** + * This method gets the category. + * + * @return the category as one of the categories in ExpenseCategory + * + */ public ExpenseCategory getCategory() { return category; } + /** + * This method gets the description. + * + * @return the description as a String + * + */ public String getDescription() { return description; } diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/GeneralBudget.java b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/GeneralBudget.java index d5965fae..84e77940 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/GeneralBudget.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/GeneralBudget.java @@ -12,7 +12,7 @@ import java.util.Calendar; import java.util.List; /** - * Class that represents GeneralBudget and implements the Budget interface. + * Class that represents GeneralBudget. * * @author Adele */ @@ -26,6 +26,8 @@ public class GeneralBudget { * The constructor of a new GeneralBudget. * * @param budgetPeriod The period the budget are going to last for + * @param listOfItems A list of BudgetItems + * @param maxAmount The maxAmount of the generalBudget as a double * */ public GeneralBudget(int budgetPeriod, List<BudgetItem> listOfItems, double maxAmount){ @@ -70,6 +72,14 @@ public class GeneralBudget { return ChronoUnit.DAYS.between((Temporal) cStart, (Temporal) cEnd); } + /** + * This method adds a budgetItem to the list of budgetItems in the generalBudget + * + * @param budgetAmount The amount of budget as a double + * @param description A description of the budget as a String + * @param category A category from ExpenseCategory + * + */ public void addToBudget(double budgetAmount, String description, ExpenseCategory category) { if (totalSum() + budgetAmount > maxAmount ){ throw new IllegalArgumentException("Amount to be added goes over the max value of the budget"); @@ -82,6 +92,14 @@ public class GeneralBudget { } } + /** + * This method checks if the list in the generalBudget already contains a budgetItem with a specified category. + * + * @param category A category from ExpenseCategory + * + * @return True if the list contains a budgetItem with this category and false if it does not + * + */ public boolean checksListOfItemsContainsBudgetItem(ExpenseCategory category){ for (BudgetItem item : listOfItems) { if (item.getCategory() == category) { @@ -91,6 +109,12 @@ public class GeneralBudget { return false; } + /** + * This method returns the totalSum of all budgetsItems in the list in the generalBudget + * + * @return the sum of the budgetsItems as a double + * + */ public double totalSum(){ double sum = 0; for (BudgetItem budgetItem : listOfItems) { @@ -99,6 +123,12 @@ public class GeneralBudget { return sum; } + /** + * This method deletes a budgetItem from the list in the GeneralBudget. + * + * @param category A category from ExpenseCategory + * + */ public void deleteItemFromBudget(ExpenseCategory category){ listOfItems.removeIf(item -> item.getCategory() == category); } -- GitLab