Skip to content
Snippets Groups Projects
Commit 491fd364 authored by Andreas's avatar Andreas
Browse files

ItemRegister class is superclass for IncomeRegister and ExpenseRegister

parent 14f7314f
No related branches found
No related tags found
2 merge requests!9Added FileHandling class for ItemRegister objects, and reworked ItemRegister with new subclasses,!8Remade ItemRegister class and made FileHandling for ItemRegister-objects with tests
package no.ntnu.idatt1002.demo.data.Economics;
import java.util.ArrayList;
import java.util.List;
/**
* Register class for storing Item-objects.
*/
public abstract class ItemRegister{
private final List<Item> items;
/**
* An "empty" class constructor.
*/
public ItemRegister(){
this.items = new ArrayList<>();
}
/**
* Class constructor.
* @param items an ArrayList with Item´s you want to overview.
*/
public ItemRegister(ArrayList<Item> items){
this.items = items;
}
/**
* Check if the register has Item´s.
* @return true or false depending on if items is empty.
*/
public boolean hasItems(){
return items.isEmpty();
}
/**
* Get the sum of all Item´s in items
* @return sum of all Item´s
*/
public double getTotalSum(){
return items.stream().map(Item::getAmount).mapToDouble(Double::doubleValue).sum();
}
}
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