// Adds to balance and creates a ledger of the transaction // by checking whether there's room in history[] and making more if needed // then changing balance, creating the ledger entry and increasing historyCount public void NewTransaction(double change, string note) { if(!(historyCount < historyCap)) { AddHistory(historyCap); } balance += change; history[historyCount] = new Ledger(DateTime.Now, change, balance, note); historyCount++; }
// Doubles capacity of history[] and size of historyCap // by creating a newHistory[] and copying the old entries into it public void AddHistory(int cap) { int newCap = cap * 2; Ledger[] newHistory = new Ledger[newCap]; for(int i = 0; i < cap; i++) { newHistory[i] = history[i]; } history = newHistory; historyCap = newCap; }
public void SetHistory(int id, Ledger _ledger) { history[id] = _ledger; }