Exemple #1
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"))
            {
                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"))
                {
                    ShowArray(bank.GetAccounts());
                }
                else if (cmd.Equals("account"))
                {
                    int     id  = iw.getInt("account id: ");
                    Account acc = bank.FindAccount(id);
                    Atm.ProcessAccount(acc);
                }
                else
                {
                    help();
                }
                cmd = iw.getString("> ");
            }
        }
Exemple #2
0
        public static void ProcessAccount(Account acc)
        {
            Console.WriteLine("balance = {0}", acc.Balance);
            string       cmd;
            InputWrapper iw = new InputWrapper();

            Console.WriteLine("Enter command, quit to exit");
            cmd = iw.getString(acc.Prompt);
            while (!cmd.Equals("quit"))
            {
                if (cmd.Equals("deposit"))
                {
                    decimal amount = iw.getDecimal("amount: ");
                    acc.Deposit(amount);
                    Console.WriteLine("balance = {0}", acc.Balance);
                }
                else if (cmd.Equals("withdraw"))
                {
                    decimal amount = iw.getDecimal("amount: ");
                    acc.Withdraw(amount);
                    Console.WriteLine("balance = {0}", acc.Balance);
                }
                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();
                }
                cmd = iw.getString(acc.Prompt);
            }
        }