Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var stock1 = new ConcreteStock(934.0, "APPL", 200);
            var stock2 = new ConcreteStock(764, "GOOL", 24);
            var stock3 = new ConcreteStock(35.2, "YAOO", 10);
            var stock4 = new ConcreteStock(8.0, "JP", 543);

            var display = new PortfolioDisplay();

            var AntonPf = new Portfolio("Anton\'s pf", display);

            AntonPf.AddStock(stock1);
            AntonPf.AddStock(stock2);
            AntonPf.AddStock(stock3);
            AntonPf.AddStock(stock4);

            display.PrintPortfolio(AntonPf);

            var thread1 = new Thread(() => StockThread(stock1));
            var thread2 = new Thread(() => StockThread(stock2));
            var thread3 = new Thread(() => StockThread(stock3));
            var thread4 = new Thread(() => StockThread(stock4));

            thread1.Start();
            thread2.Start();
            thread3.Start();
            thread4.Start();
        }
Exemplo n.º 2
0
 public void Notify(ConcreteStock stock)
 {
     foreach (var item in portfolios)
     {
         item.Update(stock);
     }
 }
Exemplo n.º 3
0
        public void AddStock(ConcreteStock stock)
        {
            stock.Attach(this);
            Stocks.Add(stock);

            TotalValue += stock.StateOfstock * stock.Amount;
        }
Exemplo n.º 4
0
        public void Update(ConcreteStock s)
        {
            TotalValue = 0;
            foreach (var item in Stocks)
            {
                TotalValue += item.StateOfstock * item.Amount;
            }

            foreach (var item in Stocks)
            {
                if (item.Name == s.Name)
                {
                    Display.PrintPortfolio(this, Stocks.IndexOf(item));
                }
            }
        }
Exemplo n.º 5
0
        public static void StockThread(ConcreteStock stock)
        {
            Random rand = new Random();

            int initialStockValue = (int)stock.StateOfstock;

            Thread.Sleep(rand.Next(1, 13) * 2000);

            for (int i = 0; i < 11; i++)
            {
                double newValue = (double)rand.Next((int)(initialStockValue * 0.95), (int)(initialStockValue * 1.05));
                stock.SetStateOfstock(newValue);

                int time = rand.Next(1, 13);
                Thread.Sleep(time * 1500);
            }

        }
Exemplo n.º 6
0
        public string PrintStock(ConcreteStock printme, bool changed = false)
        {
            string s = $"Name: {printme.Name} \t|\t Amount: {printme.Amount} \t|\t Value: {printme.StateOfstock}" + (changed != true ? "" : "\t#") + "\n";

            return(s);
        }