From 439388de62973f5e7e2edd897d0f33cc8f542058 Mon Sep 17 00:00:00 2001
From: Andreas <andreksv@ntnu.no>
Date: Sun, 5 Mar 2023 18:56:37 +0100
Subject: [PATCH] Made class for storing and getting information on Income and
 Expense

---
 .../ntnu/idatt1002/demo/TotalIncomeIdea.java  | 53 ---------------
 .../idatt1002/demo/data/ItemOverview.java     | 68 +++++++++++++++++++
 .../java/no/ntnu/idatt1002/demo/expense.java  | 14 ----
 .../java/no/ntnu/idatt1002/demo/income.java   | 14 ----
 .../java/no/ntnu/idatt1002/demo/revenue.java  | 49 -------------
 5 files changed, 68 insertions(+), 130 deletions(-)
 delete mode 100644 src/main/java/no/ntnu/idatt1002/demo/TotalIncomeIdea.java
 create mode 100644 src/main/java/no/ntnu/idatt1002/demo/data/ItemOverview.java
 delete mode 100644 src/main/java/no/ntnu/idatt1002/demo/expense.java
 delete mode 100644 src/main/java/no/ntnu/idatt1002/demo/income.java
 delete mode 100644 src/main/java/no/ntnu/idatt1002/demo/revenue.java

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 bb87775c..00000000
--- 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 00000000..ef03d1fa
--- /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 d91f1d6a..00000000
--- 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 d9a2e9f6..00000000
--- 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 40870cdb..00000000
--- 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;
-    }
-}
-- 
GitLab