Exemplo n.º 1
0
        public static EquityFactory GetInstance()
        {
            if (_instance == null)
            {
                _instance = new EquityFactory();
            }

            return(_instance);
        }
Exemplo n.º 2
0
        public void Buy(string tickerSymbol, int shares)
        {
            CashAccount account       = new CashAccount(_accountNumber);
            var         equityFactory = EquityFactory.GetInstance();
            Equity      equity        = equityFactory.CreateEquity(tickerSymbol);

            decimal amount  = equity.GetPrices() * shares;
            decimal balance = account.GetAccountBalance();

            if (balance >= amount)
            {
                account.Withdraw(amount);

                equity.Buy(shares);
                Console.WriteLine("Succesfully bought {0} {1} shares", shares, tickerSymbol);
                Console.WriteLine("New account balance is ${0}", account.GetAccountBalance());
            }
            else
            {
                Console.WriteLine("Insufficient balance ${0}", balance);
            }
        }