Created
February 9, 2018 21:37
-
-
Save bandrzejczak/b9bd1d9a0309fd7777944f36c97808bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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