Пример #1
0
        /// <summary>
        /// Prints the symbols.
        /// </summary>
        public void PrintSymbols()
        {
            Stack symbolStack = CommercialUtility.ReadStockSymbols();

            Console.WriteLine("Your Currently purchased Symbols are ");

            while (!symbolStack.IsEmpty())
            {
                Console.Write(symbolStack.Pop() + " ");
            }

            Console.WriteLine();
        }
Пример #2
0
        /// <summary>
        /// Prints the report.
        /// </summary>
        public void PrintReport()
        {
            double totalValueOfAllStock            = 0;
            List <CompanyShares> companySharesList = CommercialUtility.ReadFromFile();

            foreach (CompanyShares cs in companySharesList)
            {
                Console.WriteLine("\nStockName : " + cs.Symbol + "\nNumber of Shares: " + cs.NumberOfShares + "\nPrice Of each share: " + cs.PriceOfShare + "\nPurchased Date and Time : " + cs.DateTime);
                Console.WriteLine("\nTotal Value Of Stock " + cs.Symbol + ": " + (cs.NumberOfShares * cs.PriceOfShare));
                Console.WriteLine("--------------------------------");

                totalValueOfAllStock = totalValueOfAllStock + (cs.NumberOfShares * cs.PriceOfShare);
            }

            Console.WriteLine("\nTotal value Of all Stocks = " + totalValueOfAllStock);
        }
Пример #3
0
        /// <summary>
        /// Sells the specified symbol.
        /// </summary>
        /// <param name="symbol">The symbol.</param>
        public void Sell(string symbol)
        {
            List <CompanyShares> companySharesList = CommercialUtility.ReadFromFile();

            foreach (CompanyShares companyShares in companySharesList)
            {
                if (companyShares.Symbol.Equals(symbol))
                {
                    companySharesList.Remove(companyShares);
                    Console.WriteLine("Share with Symbol " + symbol + "removed");
                    CommercialUtility.WriteToFile(companySharesList);
                    return;
                }
            }

            Console.WriteLine("stock with Symbol " + symbol + "does not exist");
        }
Пример #4
0
        /// <summary>
        /// Buys the specified number of shares.
        /// </summary>
        /// <param name="numberOfShares">The number of shares.</param>
        /// <param name="price">The price.</param>
        /// <param name="symbol">The symbol.</param>
        public void Buy(long numberOfShares, double price, string symbol)
        {
            List <CompanyShares> companySharesList = CommercialUtility.ReadFromFile();

            foreach (CompanyShares shares in companySharesList)
            {
                if (shares.Symbol.Equals(symbol))
                {
                    Console.WriteLine("You have already bought this share with symbol " + symbol);
                    return;
                }
            }

            string        dateTime      = DateTime.Now.ToString();
            CompanyShares companyShares = new CompanyShares(numberOfShares, price, symbol, dateTime);

            companySharesList.Add(companyShares);

            CommercialUtility.WriteToFile(companySharesList);
        }