From 3fd82a1c60286e5b1debc3ec42f120c87084c076 Mon Sep 17 00:00:00 2001
From: HSoreide <sofie.scisly@gmail.com>
Date: Sun, 5 Mar 2023 10:02:03 +0100
Subject: [PATCH] Add constructors to Income and Expense classes

---
 .../no/ntnu/idatt1002/demo/data/Expense.java  | 14 ++++++-
 .../no/ntnu/idatt1002/demo/data/Income.java   | 39 ++++++++++++++++++-
 2 files changed, 49 insertions(+), 4 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 a6baabe4..72a0f5be 100644
--- a/src/main/java/no/ntnu/idatt1002/demo/data/Expense.java
+++ b/src/main/java/no/ntnu/idatt1002/demo/data/Expense.java
@@ -5,12 +5,22 @@ public class Expense extends Item{
     private ExpenseCategory category;
 
 
-    public Expense(double amount, boolean recurring) {
+    public Expense(double amount, boolean recurring, ExpenseCategory category) {
         super(amount, recurring);
+
+        if(category == null) {
+            throw new IllegalArgumentException("The income must belong to a category.");
+        }
+        this.category = category;
     }
 
-    public Expense(String description, double amount, boolean recurring) {
+    public Expense(String description, double amount, boolean recurring, ExpenseCategory category) {
         super(description, amount, recurring);
+        if(category == null) {
+            throw new IllegalArgumentException("The income must belong to a category.");
+        }
+        this.category = category;
+
     }
 
     /**
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 d01818ac..a3ba7ba2 100644
--- a/src/main/java/no/ntnu/idatt1002/demo/data/Income.java
+++ b/src/main/java/no/ntnu/idatt1002/demo/data/Income.java
@@ -1,11 +1,46 @@
 package no.ntnu.idatt1002.demo.data;
 
 public class Income extends Item{
-    public Income(double amount, boolean recurring) {
+
+    private IncomeCategory category;
+
+    public Income(double amount, boolean recurring, IncomeCategory category) {
         super(amount, recurring);
+
+        if(category == null) {
+            throw new IllegalArgumentException("The income must belong to a category.");
+        }
+        this.category = category;
     }
 
-    public Income(String description, double amount, boolean recurring) {
+    public Income(String description, double amount, boolean recurring, IncomeCategory category) {
         super(description, amount, recurring);
+        if(category == null) {
+            throw new IllegalArgumentException("The income must belong to a category.");
+        }
+        this.category = category;
+
+    }
+
+    /**
+     * 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.
+     */
+    public IncomeCategory getCategory() {
+        return category;
     }
+
+    /**
+     * 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.
+     */
+    public void setCategory(IncomeCategory category) {
+        if(category == null) {
+            throw new IllegalArgumentException("The income must belong to a category.");
+        }
+        this.category = category;
+    }
+
+
+
 }
-- 
GitLab