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

public abstract class ItemRegister<T extends Item> extends Object
ItemRegister is a generic class used for storing either Income or Expense.
Author:
andreas
  • Constructor Details

    • ItemRegister

      public ItemRegister()
      Class constructor that creates an empty List for storing item´s.
    • ItemRegister

      public ItemRegister(List<T> items)
      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

      public List<T> getItems()
      Get a List of every item.
      Returns:
      item List.
    • addItem

      public void addItem(T newItem) throws IllegalArgumentException
      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

      public void removeItem(T itemWantRemoved) throws IllegalArgumentException
      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

      public String toString()
      Overrides:
      toString in class Object