/// <summary> /// Starts the shares. /// </summary> public void InitialiseShares() { try { StockAccount stockAccount = new StockAccount(); while (true) { Console.WriteLine(); Console.WriteLine("1.Buy the Share"); Console.WriteLine("2.Sell a Share"); Console.WriteLine("3.View Existing Shares"); Console.WriteLine("4.View Symobol Purchased"); string input = Console.ReadLine(); ////Check if the choice enterd by the user contains number if (InventoryManagement.InventoryMngtUtility.IsNumber(input) == false) { Console.WriteLine("Invalid input"); continue; } ////convert that number to an integer type int option = Convert.ToInt32(input); //// Calls the method of user's choice switch (option) { case 1: InputFromUser.TakeUserInput(option); break; case 2: InputFromUser.TakeUserInput(option); break; case 3: stockAccount.PrintReport(); break; case 4: StockAccount stockaccount = new StockAccount(); stockaccount.PrintSymbols(); break; default: return; } } } catch (Exception e) { Console.WriteLine(e.Message); } }
/// <summary> /// Takes the user input. /// </summary> /// <param name="choosedOption">The option.</param> public static void TakeUserInput(int choosedOption) { StockAccount stockAccount = new StockAccount(); int numberOfShares = 0; double priceOfShare = 0; string symbol = string.Empty; string datetime = string.Empty; string stringNumberOfShares; if (choosedOption == 1) { do { Console.WriteLine("Enter the Number of shares"); stringNumberOfShares = Console.ReadLine(); }while (!InventoryManagement.InventoryMngtUtility.IsNumber(stringNumberOfShares)); while (true) { Console.WriteLine("Enter the Price Of Share"); string stringpriceOfShare = Console.ReadLine(); if (InventoryManagement.InventoryMngtUtility.IsNumber(stringpriceOfShare) == false) { Console.WriteLine("Invalid input"); continue; } priceOfShare = Convert.ToInt32(stringpriceOfShare); break; } while (true) { Console.WriteLine("Enter the Stock Symbol"); string stringSymbol = Console.ReadLine(); if (InventoryManagement.InventoryMngtUtility.CheckString(stringSymbol)) { Console.WriteLine("Stock Symbol can't be empty"); continue; } if (InventoryManagement.InventoryMngtUtility.ContainsCharacter(stringSymbol)) { Console.WriteLine("No characters allowed"); continue; } symbol = stringSymbol; break; } stockAccount.Buy(numberOfShares, priceOfShare, symbol); } if (choosedOption == 2) { while (true) { Console.WriteLine("Enter the Stock Symbol of the share you want to sell"); string stringSymbol = Console.ReadLine(); if (InventoryManagement.InventoryMngtUtility.CheckString(stringSymbol)) { Console.WriteLine("Stock Symbol cant be empty"); continue; } symbol = stringSymbol; stockAccount.Sell(symbol); break; } } }