Exemplo n.º 1
0
        static void Main(string[] args)
        {
            char option = 'z';

            Dictionary <Account, List <Owner> > CompleteList = new Dictionary <Account, List <Owner> >();


            while (option != 'x' && option != 'X')
            {
                Console.WriteLine("1: Create Savings account.");
                Console.WriteLine("2: Create Checking account.");
                Console.WriteLine("3: Print the list of all acounts nts.");
                Console.WriteLine("4: Search Existing Accounts By Owner");
                Console.WriteLine("5: Make a Deposit");
                Console.WriteLine("6: Withdraw Funds");
                Console.WriteLine("7: Check the Balance ");
                Console.WriteLine("8: Close the Account");
                Console.WriteLine("9: Check for the total amount of funds in the bank");
                Console.WriteLine("X: Exit.");

                option = Console.ReadKey().KeyChar;
                Console.WriteLine();

                switch (option)
                {
                case '1':
                {
                    Console.Clear();
                    List <Owner> owners = new List <Owner>();
                    owners.Add(GetOwnerInformationFromConsole());

                    char getMoreOwners = 'z';


                    while (getMoreOwners != 'n')
                    {
                        Console.Write("Add more owners? (y/n): ");
                        getMoreOwners = Console.ReadKey().KeyChar;
                        Console.WriteLine();
                        if (getMoreOwners == 'y')
                        {
                            owners.Add(GetOwnerInformationFromConsole());
                        }
                        else if (getMoreOwners != 'n')
                        {
                            Console.WriteLine("Please select either 'y' or 'n' from the option menu.");
                        }
                    }

                    double  balance = GetBalanceInformationFromConsole();
                    Account acc     = new SavingsAccount(balance, owners.ToArray());
                    accounts.Add(acc);
                    foreach (Owner o in owners)
                    {
                        if (!totalowners.Contains(o))
                        {
                            totalowners.Add(o);
                        }
                    }
                    OpenAccountMessage(acc);
                }

                break;

                case '2':
                {
                    Console.Clear();
                    List <Owner> owners = new List <Owner>();
                    owners.Add(GetOwnerInformationFromConsole());

                    char getMoreOwners = 'z';


                    while (getMoreOwners != 'n')
                    {
                        Console.Write("Add more owners? (y/n): ");
                        getMoreOwners = Console.ReadKey().KeyChar;
                        Console.WriteLine();
                        if (getMoreOwners == 'y')
                        {
                            owners.Add(GetOwnerInformationFromConsole());
                        }
                        else if (getMoreOwners != 'n')
                        {
                            Console.WriteLine("Please select either 'y' or 'n' from the option menu.");
                        }
                    }
                    double  balance = GetBalanceInformationFromConsole();
                    Account acc     = new CheckingAccount(owners.ToArray(), balance);

                    CompleteList.Add(acc, owners);
                    accounts.Add(acc);
                    foreach (Owner o in owners)
                    {
                        if (!totalowners.Contains(o))
                        {
                            totalowners.Add(o);
                        }
                    }
                    OpenAccountMessage(acc);
                }

                break;

                case '3':
                {
                    Console.Clear();
                    foreach (Account acc in accounts)
                    {
                        Console.WriteLine();
                        Console.WriteLine(acc.PrintAllOwners());
                    }
                }
                break;

                case '4':
                {
                    Console.Clear();
                    object getf = GetOwnerInformationFromConsole();
                    foreach (Owner todo in totalowners)
                    {
                        if (todo.Equals(getf))
                        {
                            Console.WriteLine();
                            Console.Clear();
                            Console.WriteLine(todo.PrintAllAccounts());
                        }
                    }
                }
                break;

                case '5':
                {
                    Console.Clear();
                    Account acc = GetAccountNumberFromConsole();
                    if (acc != null)
                    {
                        acc.Deposit(GetAmountFromConsole());
                    }
                }
                break;

                case '6':
                {
                    Console.Clear();
                    Account acc = GetAccountNumberFromConsole();
                    if (acc != null)
                    {
                        char tryOtherAmount = 'y';
                        do
                        {
                            try
                            {
                                if (tryOtherAmount == 'y')
                                {
                                    acc.Withdraw(GetAmountFromConsole());
                                }
                                else if (tryOtherAmount != 'n')
                                {
                                    Console.WriteLine("Please select either 'y' or 'n' from the option menu.");
                                }
                                tryOtherAmount = 'n';
                            }
                            catch (ArgumentException neg)
                            {
                                Console.WriteLine(neg.Message + "\r\n");
                                Console.Write("Try Other Amount? (y/n) ");
                                tryOtherAmount = Console.ReadKey().KeyChar;
                                Console.WriteLine();
                            }
                        } while (tryOtherAmount != 'n');
                        Console.WriteLine();
                    }
                }
                break;

                case '7':
                {
                    Console.Clear();
                    Account acc = GetAccountNumberFromConsole();
                    if (acc != null)
                    {
                        Console.WriteLine("Your balance is : {0} \r\n", acc.GetBalance());
                    }
                }
                break;

                case '8':
                {
                    Console.Clear();
                    Account acc = GetAccountNumberFromConsole();
                    if (acc != null)
                    {
                        acc.Withdraw(acc.GetBalance());
                        foreach (Owner o in totalowners)
                        {
                            if (totalowners.Contains(o))
                            {
                                o.RemoveFromMyAccounts(acc);
                            }
                        }
                        accounts.Remove(acc);
                        acc.CloseAccount();

                        CloseAccountMessage(acc);
                    }
                }
                break;

                case '9':
                {
                    Console.Clear();
                    double totalFundsInBank = 0;
                    foreach (Account a in accounts)
                    {
                        totalFundsInBank += a.GetBalance();
                    }

                    Console.WriteLine("Total amount of funds in the bank: {0} \r\n", totalFundsInBank);
                }
                break;
                }
            }
        }