Esempio n. 1
0
        public void RealizationOfOrders(BrokersChoices selectedNameOfStockByUser, int amountForPurchaseOfStocks)
        {
            string brokersChoice = selectedNameOfStockByUser.SelectedNameOfStockByBroker;
            int    priceOfStockSelectedByBroker = 0;

            foreach (Stock stock in stocks)
            {
                string nameStock = stock.NameOfStock;

                if (brokersChoice == nameStock)
                {
                    priceOfStockSelectedByBroker = stock.StockPrice;
                    break;
                }
            }

            int totalAmountForPurchasedStocks = priceOfStockSelectedByBroker * selectedNameOfStockByUser.AnInterestingQuantityOfStocksByBroker;

            Console.WriteLine("Do zapłaty za zakupione akcje jest: " + totalAmountForPurchasedStocks);
            Console.WriteLine();

            int brokersAmountForPurchaseOfStocks = amountForPurchaseOfStocks;

            int remainingPartOfBrokersAmountDesignatedForPurchaseOfStocks = brokersAmountForPurchaseOfStocks - totalAmountForPurchasedStocks;

            selectedNameOfStockByUser.BrokersAmountDesignatedForPurchaseOfStocks = remainingPartOfBrokersAmountDesignatedForPurchaseOfStocks;

            Console.WriteLine("Z przeznaczonej kwoty na zakupy akcji pozostało: " + selectedNameOfStockByUser.BrokersAmountDesignatedForPurchaseOfStocks);
            Console.WriteLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            List <Stock> stock = new List <Stock>();

            stock.Add(new Stock()
            {
                NameOfStock = "A", QuantityOfStock = 10, StockPrice = 50
            });
            stock.Add(new Stock()
            {
                NameOfStock = "B", QuantityOfStock = 5, StockPrice = 100
            });
            stock.Add(new Stock()
            {
                NameOfStock = "C", QuantityOfStock = 15, StockPrice = 20
            });
            stock.Add(new Stock()
            {
                NameOfStock = "D", QuantityOfStock = 20, StockPrice = 250
            });
            stock.Add(new Stock()
            {
                NameOfStock = "E", QuantityOfStock = 2, StockPrice = 80
            });

            Broker        broker        = new Broker();
            StockExchange stockExchange = new StockExchange(broker, stock);

            int            amountForPurchaseOfStocks = stockExchange.StartSession();
            BrokersChoices selectedNameOfStockByUser = stockExchange.AcceptanceOfOrdersForStocks();

            stockExchange.RealizationOfOrders(selectedNameOfStockByUser, amountForPurchaseOfStocks);
            stockExchange.EndOfSession();

            Console.Read();
        }
Esempio n. 3
0
        public BrokersChoices AcceptanceOfOrdersForStocks()
        {
            bool   wasItChosen = false;
            string UserChoice;

            Console.WriteLine("Proszę podać nazwę akcji");
            do
            {
                UserChoice = Console.ReadLine();

                if (UserChoice.Contains(" "))
                {
                    Console.WriteLine("Musisz podać nazwę akcji, aby zostało zrealizowane zamówienie");
                }
                else
                {
                    foreach (Stock stock in stocks)
                    {
                        string nameStock = stock.NameOfStock;

                        if (UserChoice == nameStock)
                        {
                            UserChoice = nameStock;
                            Console.WriteLine("Dziękujemy za wybór");
                            wasItChosen = true;
                            break;
                        }
                    }
                }

                if (wasItChosen == false)
                {
                    Console.WriteLine("Takiej nazwy akcji nie ma w bazie danych");
                    Console.WriteLine("Spróbuj ponownie podać nazwę");
                }
            } while (wasItChosen == false);

            bool isItNumber = false;
            int  quantityGivenByUser;
            bool hasBeenQuantityGive = false;

            do
            {
                Console.WriteLine("Podaj interesującą Cię ilość wybranej akcji");

                isItNumber = int.TryParse(Console.ReadLine(), out quantityGivenByUser);

                if (isItNumber == false)
                {
                    Console.WriteLine("Ilość musi być liczbą. Podaj liczbę.");
                }
                else
                {
                    foreach (Stock stock in stocks)
                    {
                        string nameStock = stock.NameOfStock;

                        if (UserChoice == nameStock)
                        {
                            if (quantityGivenByUser < stock.QuantityOfStock)
                            {
                                Console.WriteLine("Dodano " + quantityGivenByUser + " akcji o nazwie " + UserChoice + " do koszyka");
                                Console.WriteLine();
                                hasBeenQuantityGive = true;
                                break;
                            }
                            else
                            {
                                Console.WriteLine("Niestety nie mamy tylu akcji :( ");
                                break;
                            }
                        }
                    }
                }
            } while (hasBeenQuantityGive == false);

            BrokersChoices brokersChoices = new BrokersChoices();

            brokersChoices.SelectedNameOfStockByBroker           = UserChoice;
            brokersChoices.AnInterestingQuantityOfStocksByBroker = quantityGivenByUser;

            return(brokersChoices);
        }