public void sell() { for (Company x : _market.getCompanies()) { if (x.getRisk() > _confidence || x.numLeft() < 3 || x.getRisk() < _confidence - 15) { if (_stocks.get(x) == 1) { _stocks.remove(x); } else { _stocks.put(x, _stocks.get(x) - 1); } _money += x.getPrice(); x.gain(); break; } else { _happy = true; } } }
public void invest() { _oldmoney = _money; // assuming this goes first. for (Company y : _market.getCompanies()) { if (y.getRisk() < _confidence && y.numLeft() > 0 && y.getPrice() < _money) { if (_stocks.containsKey(y)) { _stocks.put(y, (_stocks.get(y) + 1)); } else { _stocks.put(y, 1); } y.sell(); _money -= y.getPrice(); break; } else { _happy = true; } } }