Class Savings
java.lang.Object
no.ntnu.idatt1002.demo.data.budget.Savings
Savings is a class that has an amount that is given to it, which can further can be given to
different savingsGoals.
-
Constructor Summary
ConstructorsConstructorDescriptionSavings()
Class constructor that sets savingsGoals to an empty ArrayList and amount to zero.Savings
(double amount) Class constructor that sets savingsGoals to an empty ArrayList and amount to a given double.Savings
(ArrayList<SavingsGoal> savingsGoals) Class constructor that sets savingsGoals to a given ArrayList and amount to zero.Savings
(ArrayList<SavingsGoal> savingsGoals, double amount) Class constructor that sets savingsGoals to a given ArrayList and amount to a given double. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addSavingsGoal
(SavingsGoal savingsGoal) Add a SavingsGoal to Savings.void
addToSavings
(double amount) Add an amount to Savings.void
addToSavingsGoal
(int amount, SavingsGoal savingsGoal) Method for adding an amount to a SavingsGoal.A List of all SavingsGoal that are achieved.double
Get the amount.getSavingsGoal
(SavingsGoal savingsGoal) Get a specific SavingsGoal from savingsGoals.Get List of SavingsGoals.double
Get the total amount invested into SavingsGoals and the amount that is unused.boolean
hasSavingsGoal
(SavingsGoal savingsGoal) Method to check if savingsGoals contains a specific SavingsGoal.
-
Constructor Details
-
Savings
public Savings()Class constructor that sets savingsGoals to an empty ArrayList and amount to zero. -
Savings
public Savings(double amount) Class constructor that sets savingsGoals to an empty ArrayList and amount to a given double.- Parameters:
amount
- the double you want to assign amount
-
Savings
Class constructor that sets savingsGoals to a given ArrayList and amount to zero.- Parameters:
savingsGoals
- the ArrayList you want to assign savingsGoals
-
Savings
Class constructor that sets savingsGoals to a given ArrayList and amount to a given double.- Parameters:
savingsGoals
- the ArrayList you want to assign savingsGoalsamount
- The amount of the saving.
-
-
Method Details
-
getSavingsGoals
Get List of SavingsGoals.- Returns:
- List of SavingsGoals
-
getAmount
public double getAmount()Get the amount.- Returns:
- savings amount
-
getTotalSavings
public double getTotalSavings()Get the total amount invested into SavingsGoals and the amount that is unused.- Returns:
- amount invested into SavingsGoals and amount not used.
-
getSavingsGoal
Get a specific SavingsGoal from savingsGoals.- Parameters:
savingsGoal
- the SavingsGoal you want to get- Returns:
- the SavingsGoal you wanted to find if it exists
- Throws:
IllegalArgumentException
- if the SavingsGoal is not in the List
-
hasSavingsGoal
Method to check if savingsGoals contains a specific SavingsGoal.- Parameters:
savingsGoal
- the SavingsGoal you want to check.- Returns:
- boolean depending on if savingsGoals contains the savingsGoal.
-
getAchievedSavingsGoal
A List of all SavingsGoal that are achieved. A SavingsGoal is achieved if its amount is zero.- Returns:
- List of achieved SavingsGoal
-
addToSavingsGoal
Method for adding an amount to a SavingsGoal.- Parameters:
amount
- the amount you want to addsavingsGoal
- the SavingsGoal you want to add to- Throws:
IllegalArgumentException
- if the amount is higher than the Savings amount.IllegalArgumentException
- if SavingsGoal is not in savingsGoal.
-
addToSavings
public void addToSavings(double amount) Add an amount to Savings.- Parameters:
amount
- the amount you want to add.
-
addSavingsGoal
Add a SavingsGoal to Savings.- Parameters:
savingsGoal
- the SavingsGoal you want to add.- Throws:
IllegalArgumentException
- if the SavingsGoal already exists in the Savings.
-