diff --git a/src/main/java/no/ntnu/idatt1002/demo/Income.java b/src/main/java/no/ntnu/idatt1002/demo/Income.java new file mode 100644 index 0000000000000000000000000000000000000000..71f3a3a10567ac28c3c1145c4f4e5b195cd3b001 --- /dev/null +++ b/src/main/java/no/ntnu/idatt1002/demo/Income.java @@ -0,0 +1,53 @@ +package no.ntnu.idatt1002.demo; + +/** + * Income is for registering information about your income, + * and editing it. + * @author Andreas + */ +public class Income { + private double totalIncome; + private final double fixedIncome; + + /** + * Class constructor + * @param fixedIncome An income which you will always receive, for example a loan. + */ + protected Income(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/IncomeOverview.java b/src/main/java/no/ntnu/idatt1002/demo/IncomeOverview.java deleted file mode 100644 index baf6235509ab659076db38bb3ad51b55e9488a40..0000000000000000000000000000000000000000 --- a/src/main/java/no/ntnu/idatt1002/demo/IncomeOverview.java +++ /dev/null @@ -1,11 +0,0 @@ -package no.ntnu.idatt1002.demo; - -public class IncomeOverview { - private double income; - private final double fixedIncome; - - public IncomeOverview(double fixedIncome){ - this.income = fixedIncome; - this.fixedIncome = fixedIncome; - } -}