Skip to content
Snippets Groups Projects
Commit 3fd82a1c authored by HSoreide's avatar HSoreide
Browse files

Add constructors to Income and Expense classes

parent 8e075f15
No related branches found
No related tags found
1 merge request!3Hs item class
......@@ -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;
}
/**
......
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;
}
}
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