From 3831b9523da8af0101aa1255621d6ab1ee796119 Mon Sep 17 00:00:00 2001 From: Andreas <andreksv@ntnu.no> Date: Thu, 2 Mar 2023 12:57:59 +0100 Subject: [PATCH] Added javadoc, get- and add methods --- .../java/no/ntnu/idatt1002/demo/Income.java | 53 +++++++++++++++++++ .../ntnu/idatt1002/demo/IncomeOverview.java | 11 ---- 2 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 src/main/java/no/ntnu/idatt1002/demo/Income.java delete mode 100644 src/main/java/no/ntnu/idatt1002/demo/IncomeOverview.java 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 00000000..71f3a3a1 --- /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 baf62355..00000000 --- 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; - } -} -- GitLab