diff --git a/src/main/java/no/ntnu/idatt1002/demo/TotalIncomeIdea.java b/src/main/java/no/ntnu/idatt1002/demo/TotalIncomeIdea.java deleted file mode 100644 index bb87775c2fcbc38806412c626a79bfe4b59a4e08..0000000000000000000000000000000000000000 --- a/src/main/java/no/ntnu/idatt1002/demo/TotalIncomeIdea.java +++ /dev/null @@ -1,53 +0,0 @@ -package no.ntnu.idatt1002.demo; - -/** - * Income is for registering information about your income, - * and editing it. - * @author Andreas - */ -public class TotalIncomeIdea { - private double totalIncome; - private final double fixedIncome; - - /** - * Class constructor - * @param fixedIncome An income which you will always receive, for example a loan. - */ - protected TotalIncomeIdea(double fixedIncome){ - if(fixedIncome<0){ - throw new IllegalArgumentException("You can not have a negativ income"); - } - this.totalIncome = fixedIncome; - this.fixedIncome = fixedIncome; - } - - /** - * Return the fixed income of the income. - * @return The incomeĀ´s fixed income. - */ - public double getFixedIncome() { - double copyFixedIncome = fixedIncome; - return copyFixedIncome; - } - - /** - * Return the total income. - * @return The total income. - */ - public double getIncome() { - double copyIncome = totalIncome; - return copyIncome; - } - - /** - * Adding an amount to your total income. - * If the amount is negativ an IllegalArgumentException is thrown - * @param amount The amount you want to add to your total income. - */ - public void addIncome(double amount){ - if(amount<0){ - throw new IllegalArgumentException("You can not add a negative amount to income"); - } - totalIncome+=amount; - } -} diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/ItemOverview.java b/src/main/java/no/ntnu/idatt1002/demo/data/ItemOverview.java new file mode 100644 index 0000000000000000000000000000000000000000..ef03d1faff06e3714b585c31bb88a676007bb21d --- /dev/null +++ b/src/main/java/no/ntnu/idatt1002/demo/data/ItemOverview.java @@ -0,0 +1,68 @@ +package no.ntnu.idatt1002.demo.data; + +import java.util.ArrayList; + +/** + * RevenueOverview is a class for storing and getting + * information on your total income and expense. + */ +public class ItemOverview { + ArrayList<Income> income; + ArrayList<Expense> expense; + + /** + * The class constructor. + */ + public ItemOverview(){ + this.income = new ArrayList<>(); //ArrayList for storing income + this.expense = new ArrayList<>(); //ArrayList for storing expense + } + + /** + * Get an ArrayList of every income. + * @return Income ArrayList. + */ + public ArrayList<Income> getIncome() { + return income; + } + + /** + * Get an ArrayList of every expense. + * @return Expense ArrayList. + */ + public ArrayList<Expense> getExpense() { + return expense; + } + + /** + * Add an Income object to income. + * @param newIncome The Income you want to add. + */ + public void addIncome(Income newIncome){ + income.add(newIncome); + } + + /** + * Add an Expense object to income. + * @param newExpense The Expense you want to add. + */ + public void addExpense(Expense newExpense){ + expense.add(newExpense); + } + + /** + * Get the sum of all Income in income. + * @return Sum of all Income. + */ + public double getTotalIncome(){ + return income.stream().map(Item::getAmount).mapToDouble(Double::doubleValue).sum(); + } + + /** + * Get the sum of all Expense in expense. + * @return Sum of all Expense. + */ + public double getTotalExpense(){ + return expense.stream().map(Item::getAmount).mapToDouble(Double::doubleValue).sum(); + } +} diff --git a/src/main/java/no/ntnu/idatt1002/demo/expense.java b/src/main/java/no/ntnu/idatt1002/demo/expense.java deleted file mode 100644 index d91f1d6a6e01603ca4d6d1a614662480f4b1b56c..0000000000000000000000000000000000000000 --- a/src/main/java/no/ntnu/idatt1002/demo/expense.java +++ /dev/null @@ -1,14 +0,0 @@ -package no.ntnu.idatt1002.demo; - -public class expense extends revenue{ - /** - * The class constructor. - * - * @param category A general explanation for the change in revenue. - * @param description A more specific explanation of the change in revenue. - * @param amount The amount the revenue is changed. - */ - protected expense(String category, String description, double amount) { - super(category, description, amount); - } -} diff --git a/src/main/java/no/ntnu/idatt1002/demo/income.java b/src/main/java/no/ntnu/idatt1002/demo/income.java deleted file mode 100644 index d9a2e9f65928b91d89c865255f9e7605c5e92299..0000000000000000000000000000000000000000 --- a/src/main/java/no/ntnu/idatt1002/demo/income.java +++ /dev/null @@ -1,14 +0,0 @@ -package no.ntnu.idatt1002.demo; - -public class income extends revenue{ - /** - * The class constructor. - * - * @param category A general explanation for the change in revenue. - * @param description A more specific explanation of the change in revenue. - * @param amount The amount the revenue is changed. - */ - protected income(String category, String description, double amount) { - super(category, description, amount); - } -} diff --git a/src/main/java/no/ntnu/idatt1002/demo/revenue.java b/src/main/java/no/ntnu/idatt1002/demo/revenue.java deleted file mode 100644 index 40870cdb364da3e61ef4b4441297d0a648c7f928..0000000000000000000000000000000000000000 --- a/src/main/java/no/ntnu/idatt1002/demo/revenue.java +++ /dev/null @@ -1,49 +0,0 @@ -package no.ntnu.idatt1002.demo; - -/** - * Revenue is a Superclass for both income - * and expense. It is for registering a change in - * revenue. - * @author Andreas - */ -public class revenue { - private String category; - private String description; - private double amount; - - /** - * The class constructor. - * @param category A general explanation for the change in revenue. - * @param description A more specific explanation of the change in revenue. - * @param amount The amount the revenue is changed. - */ - protected revenue(String category, String description, double amount){ - this.category = category; - this.description = description; - this.amount = amount; - } - - /** - * Return the category of the revenue change. - * @return The revenue change category. - */ - public String getCategory() { - return category; - } - - /** - * Return the description of the revenue change. - * @return The revenue change description. - */ - public String getDescription() { - return description; - } - - /** - * Return the amount of the revenue change. - * @return The revenue change amount. - */ - public double getAmount() { - return amount; - } -}