public void BuyOffer(Stock stock, int shares, int code) { bool stockBought = false; // see if someone is willing to buy: for (int i = 0; i < sellOffers.Count; i++) { StockOffer offer = sellOffers[i]; // check if the stock is the same: if (offer.stock == stock && offer.stockShares == shares) { Debug.Log(shares + " shares of " + stock + " stocks bought by colleague with code " + code); sellOffers.Remove(offer); stockBought = true; } if (stockBought) { break; } } if (!stockBought) { Debug.Log(shares + " shares of " + stock + " stocks added to inventory"); StockOffer offer = new StockOffer(shares, stock, code); buyOffers.Add(offer); } }
public void SaleOffer(string stock, int shares, int colleagueCode) { Boolean stockSold = false; foreach (var offer in stockBuyOffers) { if (offer.getStockSymbol() == stock && offer.getStockShares() == shares) { Console.WriteLine($"{shares} shares of {stock} sold to colleague code {offer.getColleagueCode()}"); stockBuyOffers.Remove(offer); stockSold = true; } if (stockSold) { break; } } if (!stockSold) { Console.WriteLine($"{shares} share of {stock} added to inventory "); StockOffer newOffering = new StockOffer(shares, stock, colleagueCode); stockSellOffers.Add(newOffering); } }
public void SaleOffer(Stock stock, int shares, int code) { bool stockSold = false; // see if someone is willing to buy: for(int i = 0; i < buyOffers.Count; i++) { StockOffer offer = buyOffers[i]; // check if the stock is the same: if(offer.stock == stock && offer.stockShares == shares) { Debug.Log (shares + " shares of " + stock + " stocks sold to colleague with code " + code); buyOffers.Remove(offer); stockSold = true; } if(stockSold) break; } if(!stockSold) { Debug.Log (shares + " shares of " + stock + " stocks added to inventory"); StockOffer offer = new StockOffer(shares, stock, code); sellOffers.Add (offer); } }