Skip to content
Snippets Groups Projects
Commit d02e6617 authored by Adele Iren Westrum Kjølstad's avatar Adele Iren Westrum Kjølstad
Browse files

Adds javadoc to BudgetItem and GeneralBudget

parent 5a17d7d8
No related branches found
No related tags found
1 merge request!11Budget
Pipeline #210644 passed
......@@ -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;
}
......
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment