/// <summary> /// creates a new portfolio /// </summary> /// <param name="n">name of the new portfolio</param> public void NewPortfolio(string n) { Portfolio temp = new Portfolio(n); portfolios.Add(temp); }
/// <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); } }