/// <summary> /// asks what the user wants to do with the porfolio balance and does said task /// </summary> /// <param name="account">user's account</param> static void PortfolioBalance(Account account) { bool exit = false; bool exit2 = false; if (account.portfolios.Count < 1) { Console.WriteLine("You dont have any portfolios"); return; } while (!exit2) { string answer; foreach (Portfolio po in account.portfolios) { Console.WriteLine(po.Name); } Console.Write("Please choose a portfolio(Case sensitive): "); answer = Console.ReadLine(); Console.WriteLine(); Portfolio p = account.GetPortfolio(answer); if (p.Name == "error") { Console.WriteLine("Invalid Portfolio"); return; } exit = false; while (!exit) { Console.WriteLine("Would you like to:"); Console.WriteLine("1. See the portfolio balance"); Console.WriteLine("2. see the cash and positions balance"); Console.WriteLine("3. See a Gain/Losses Report (unavailable)"); Console.WriteLine("4. Choose another portfolio"); Console.WriteLine("5. Return to Main Menu"); Console.Write("Please choose a number (1-5): "); answer = Console.ReadLine(); Console.WriteLine(); if (answer == "1") { p.CheckBal(account.Total); } else if (answer == "2") { p.CheckPosBal(); } else if (answer == "3") { p.GenerateReport(); } else if (answer == "4") { exit = true; } else if (answer == "5") { exit2 = true; exit = true; } else { Console.WriteLine("Invalid Answer."); } } } }
/// <summary> /// withdraws money from the account /// </summary> /// <param name="amount">the amoung to withdraw</param> /// <returns>wether the withdraw if valid or not</returns> public bool Withdraw(double amount) { if (_totalBalance - amount < 0) { return(false); } else { _totalBalance -= (amount + TRANSFERFEE); if (_cashBalance - (amount + TRANSFERFEE) < 0) { double over = (_cashBalance - (amount + TRANSFERFEE)) * -1; _cashBalance = 0; if (current.Name == null) { Console.WriteLine("You are withdrawing " + over + " more than your cash balance"); string entry = null; bool good = false; while (!good) { CheckPosBal(); Console.Write("What portfolio would you like to take from: "); entry = Console.ReadLine(); if (GetPortfolio(entry).Name != "error") { good = true; } else { Console.WriteLine("Invalid portfolio, please try again"); } } current = GetPortfolio(entry); current.CheckPosBal(); good = false; Stock st = new Stock(null, null, 0); while (!good) { Console.Write("Please choose a stock ticker to sell: "); st = current.getStockT(Console.ReadLine()); if (st != null) { good = true; } else { Console.WriteLine("Invalid ticker, please try again."); } } double a; int num = Convert.ToInt16(over / st.Price); if (over % st.Price != 0) { num++; } if (current.Sell(num, st, out a)) { _cashBalance = a - over; } } else { Console.WriteLine("You are withdrawing " + over + " more than your cash balance\nWhat stock would you like to sell(use the ticker value): "); string entry = Console.ReadLine(); Stock s = current.getStock(entry); if (s == null) { return(false); } else { double extra = 0; int am = Convert.ToInt32(over / s.Price); current.Sell(am, s, out extra); _cashBalance = extra - over; } } } else { _cashBalance -= (amount + TRANSFERFEE); } transactions++; return(true); } }