Class ItemRegister<T extends Item>
java.lang.Object
no.ntnu.idatt1002.demo.data.economics.ItemRegister<T>
- Type Parameters:
T
- Income or Expense
- Direct Known Subclasses:
ExpenseRegister
,IncomeRegister
ItemRegister is a generic class used for storing either Income or Expense.
- Author:
- andreas
-
Constructor Summary
ConstructorsConstructorDescriptionClass constructor that creates an empty List for storing item´s.ItemRegister
(List<T> items) Class constructor that takes in a List of T=(Income or Expense) as argument. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a new item to the register.getItems()
Get a List of every item.double
Get the sum of all T´s=(Income or Expenses) in items.boolean
isEmpty()
Check if items is empty.void
removeItem
(T itemWantRemoved) Remove an item from the register.toString()
-
Constructor Details
-
ItemRegister
public ItemRegister()Class constructor that creates an empty List for storing item´s. -
ItemRegister
Class constructor that takes in a List of T=(Income or Expense) as argument.- Parameters:
items
- the List of T=(Income or Expense) you want to register.
-
-
Method Details
-
getItems
Get a List of every item.- Returns:
- item List.
-
addItem
Add a new item to the register.- Parameters:
newItem
- the item you want to add.- Throws:
IllegalArgumentException
- if newItem is already in the register.
-
removeItem
Remove an item from the register.- Parameters:
itemWantRemoved
- the item you want to remove.- Throws:
IllegalArgumentException
- if the itemWantRemoved is not in the register.
-
isEmpty
public boolean isEmpty()Check if items is empty.- Returns:
- true or false depending on if items is empty.
-
getTotalSum
public double getTotalSum()Get the sum of all T´s=(Income or Expenses) in items.- Returns:
- sum of all the T´s=(Income or Expenses).
-
toString
-