Skip to content
Snippets Groups Projects
Commit 439388de authored by Andreas's avatar Andreas
Browse files

Made class for storing and getting information on Income and Expense

parent 6f92f8dd
No related branches found
No related tags found
1 merge request!4ItemOverview class (with test class)
Pipeline #202376 passed
package no.ntnu.idatt1002.demo;
/**
* Income is for registering information about your income,
* and editing it.
* @author Andreas
*/
public class TotalIncomeIdea {
private double totalIncome;
private final double fixedIncome;
/**
* Class constructor
* @param fixedIncome An income which you will always receive, for example a loan.
*/
protected TotalIncomeIdea(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;
}
}
package no.ntnu.idatt1002.demo.data;
import java.util.ArrayList;
/**
* RevenueOverview is a class for storing and getting
* information on your total income and expense.
*/
public class ItemOverview {
ArrayList<Income> income;
ArrayList<Expense> expense;
/**
* The class constructor.
*/
public ItemOverview(){
this.income = new ArrayList<>(); //ArrayList for storing income
this.expense = new ArrayList<>(); //ArrayList for storing expense
}
/**
* Get an ArrayList of every income.
* @return Income ArrayList.
*/
public ArrayList<Income> getIncome() {
return income;
}
/**
* Get an ArrayList of every expense.
* @return Expense ArrayList.
*/
public ArrayList<Expense> getExpense() {
return expense;
}
/**
* Add an Income object to income.
* @param newIncome The Income you want to add.
*/
public void addIncome(Income newIncome){
income.add(newIncome);
}
/**
* Add an Expense object to income.
* @param newExpense The Expense you want to add.
*/
public void addExpense(Expense newExpense){
expense.add(newExpense);
}
/**
* Get the sum of all Income in income.
* @return Sum of all Income.
*/
public double getTotalIncome(){
return income.stream().map(Item::getAmount).mapToDouble(Double::doubleValue).sum();
}
/**
* Get the sum of all Expense in expense.
* @return Sum of all Expense.
*/
public double getTotalExpense(){
return expense.stream().map(Item::getAmount).mapToDouble(Double::doubleValue).sum();
}
}
package no.ntnu.idatt1002.demo;
public class expense extends revenue{
/**
* The class constructor.
*
* @param category A general explanation for the change in revenue.
* @param description A more specific explanation of the change in revenue.
* @param amount The amount the revenue is changed.
*/
protected expense(String category, String description, double amount) {
super(category, description, amount);
}
}
package no.ntnu.idatt1002.demo;
public class income extends revenue{
/**
* The class constructor.
*
* @param category A general explanation for the change in revenue.
* @param description A more specific explanation of the change in revenue.
* @param amount The amount the revenue is changed.
*/
protected income(String category, String description, double amount) {
super(category, description, amount);
}
}
package no.ntnu.idatt1002.demo;
/**
* Revenue is a Superclass for both income
* and expense. It is for registering a change in
* revenue.
* @author Andreas
*/
public class revenue {
private String category;
private String description;
private double amount;
/**
* The class constructor.
* @param category A general explanation for the change in revenue.
* @param description A more specific explanation of the change in revenue.
* @param amount The amount the revenue is changed.
*/
protected revenue(String category, String description, double amount){
this.category = category;
this.description = description;
this.amount = amount;
}
/**
* Return the category of the revenue change.
* @return The revenue change category.
*/
public String getCategory() {
return category;
}
/**
* Return the description of the revenue change.
* @return The revenue change description.
*/
public String getDescription() {
return description;
}
/**
* Return the amount of the revenue change.
* @return The revenue change amount.
*/
public double getAmount() {
return amount;
}
}
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