Skip to content

Instantly share code, notes, and snippets.

@bandrzejczak
Created February 9, 2018 21:37
Show Gist options
  • Select an option

  • Save bandrzejczak/b9bd1d9a0309fd7777944f36c97808bf to your computer and use it in GitHub Desktop.

Select an option

Save bandrzejczak/b9bd1d9a0309fd7777944f36c97808bf to your computer and use it in GitHub Desktop.
public class ArrayListStockExchange implements StockExchange {
private List<Trade> trades = new ArrayList<>();
@Override
public void order(int ticket, int amount, int price, boolean buy) {
trades.add(new Trade(ticket, amount, price, buy));
}
@Override
public double dayBalance() {
double balance = 0;
for (Trade trade : trades) {
balance += trade.amount * trade.price * (trade.buy ? 1 : -1);
}
return balance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment