Beispiel #1
0
        public void ReceiveStock()
        {
            Random rand = new Random();

            //randomlly generate stock price
            //subscribers are modified
            googleStock = (float)rand.Next(1000);
            amazonStock = (float)rand.Next(1000);
            teslaStock  = (float)rand.Next(1000);

            Console.WriteLine("Stocks Received: ");
            Console.WriteLine("Google: " + googleStock + " Amazon: " + amazonStock + " Tesla: " + teslaStock);

            StockEventArgs stock = new StockEventArgs(googleStock, amazonStock, teslaStock);

            if (StockChanged != null)
            {
                StockChanged(this, stock);
            }
        }
Beispiel #2
0
        public void BuyStock(object stock, StockEventArgs s)
        {
            Console.WriteLine("Buyer: New Stock List.");
            Console.WriteLine("Google: " + s.googleStock + " Amazon: " + s.amazonStock);

            if (s.googleStock > 500)
            {
                Console.WriteLine("Buying google stock.");
            }
            else
            {
                Console.WriteLine("Not buying google stock.");
            }
            if (s.amazonStock > 300)
            {
                Console.WriteLine("Buying amazon stock.");
            }
            else
            {
                Console.WriteLine("Not buying amazon stock.");
            }
        }