예제 #1
0
        public static void ProcessAccount(Account acc)
        {
            ShowBalance(acc);
            string       cmd;
            InputWrapper iw = new InputWrapper();

            Console.WriteLine("Enter command, quit to exit");
            cmd = iw.getString(acc.Prompt);
            while (!cmd.Equals("quit"))
            {
                try
                {
                    if (cmd.Equals("deposit"))
                    {
                        decimal amount = iw.getDecimal("amount: ");
                        acc.Deposit(amount);
                        ShowBalance(acc);
                    }
                    else if (cmd.Equals("withdraw"))
                    {
                        decimal amount = iw.getDecimal("amount: ");
                        acc.Withdraw(amount);
                        ShowBalance(acc);
                    }
                    else if (cmd.Equals("owner"))
                    {
                        string owner = iw.getString("new owner name: ");
                        acc.Owner = owner;
                        show(acc);
                    }
                    else if (cmd.Equals("show"))
                    {
                        show(acc);
                    }
                    else
                    {
                        accountHelp();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    if (e.InnerException != null)
                    {
                        Console.WriteLine(e.InnerException.Message);
                    }
                }
                cmd = iw.getString(acc.Prompt);
            }
        }
예제 #2
0
        public static void DisplayTest()
        {
            Bank         bank = new Bank();
            InputWrapper iw   = new InputWrapper();
            string       cmd;

            Console.WriteLine("Enter command, quit to exit");
            cmd = iw.getString("> ");
            while (!cmd.Equals("quit"))
            {
                try
                {
                    if (cmd.Equals("open"))
                    {
                        AccountType type;
                        string      stype = iw.getString("account type: ");
                        switch (stype)
                        {
                        case "checking":
                            type = AccountType.Checking;
                            break;

                        case "savings":
                            type = AccountType.Savings;
                            break;

                        default:
                            type = AccountType.Invalid;
                            break;
                        }
                        if (type == AccountType.Invalid)
                        {
                            Console.WriteLine("Valid account types are checking/savings");
                            continue;
                        }
                        decimal bal   = iw.getDecimal("starting balance: ");
                        string  owner = iw.getString("owner: ");
                        int     id    = bank.AddAccount(type, bal, owner);
                        Console.WriteLine("Account opened, id = {0}", id);
                    }
                    else if (cmd.Equals("close"))
                    {
                        int id = iw.getInt("account id: ");
                        bank.DeleteAccount(id);
                    }
                    else if (cmd.Equals("show"))
                    {
                        ShowAccounts(bank.GetAccounts());
                    }
                    else if (cmd.Equals("account"))
                    {
                        int     id  = iw.getInt("account id: ");
                        Account acc = bank.FindAccount(id);
                        Atm.ProcessAccount(acc);
                    }
                    else if (cmd.Equals("month"))
                    {
                        ShowStringList(bank.GetStatements());
                    }
                    else
                    {
                        help();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    if (e.InnerException != null)
                    {
                        Console.WriteLine(e.InnerException.Message);
                    }
                }
                cmd = iw.getString("> ");
            }
        }