コード例 #1
0
        //public Exception AccountTypeNotFoundException { get; private set; }

        public Account OpenAccount(string accountType)
        {
            if (accountType == null)
            {
                return(null);
            }

            Account account = null;

            switch (accountType.ToLower())
            {
            case "base":
                account = new BaseAccount();
                break;

            case "gold":
                account = new GoldAccount();
                break;

            case "premium":
                account = new PremiumAccount();
                break;

            default:
                throw new NotImplementedException();
            }

            return(account);
        }
コード例 #2
0
        private void btnPremiumAccount_Click(object sender, EventArgs e)
        {
            //// create account with vaild values
            PremiumAccount b1 = new PremiumAccount(123, 100, "Premium Account", 5, 150);

            // test get accessors
            string Display = "Testing Get Accessors for Savings Account: " +
                             "\nClient Name: " + b1.ClientName +
                             "\nAccount Number: " + b1.AccountNumber +
                             "\nDate Open: " + b1.DateOpen +
                             "\nBalance: " + b1.Balance +
                             "\nFee: " + b1.Fee +
                             "\nOverdraft Amount: " + b1.OverDraft;

            //// test set accessors - valid data
            b1.ClientName = "J Doe";
            b1.Fee        = 15m;
            b1.OverDraft  = 200m;
            Display      += "\n\nTest Set Accessors: Name = J Doe, Fee = $15, Overdraft = $200" +
                            "\nNew Name: " + b1.ClientName +
                            "\nNew Fee: " + b1.Fee +
                            "\nNew Overdraft Amount: " + b1.OverDraft;

            //// test set accessors - invalid data
            b1.ClientName = "";
            b1.Fee        = 5m;
            b1.OverDraft  = 50m;
            Display      += "\n\nTest Set Accessors: Name = null, Fee = $5, Overdraft = $50" +
                            "\nNew Name: " + b1.ClientName +
                            "\nNew Fee: " + b1.Fee +
                            "\nNew Overdraft Amount: " + b1.OverDraft;

            //// test ToString() method
            Display += "\n\nToString():\n" + b1.ToString();

            //// test Deposit method
            decimal deposit = b1.Deposit(20m);

            Display += "\n\nDeposit $20, Deposit: " + deposit;
            deposit  = b1.Deposit(-30m);
            Display += "\nDeposit -$30, Deposit: " + deposit +
                       "\nBalance: " + b1.Balance;

            //// test Withdraw method
            decimal withdraw = b1.Withdraw(20m);

            Display += "\n\nWithdraw $20, Withdraw: " + withdraw;
            withdraw = b1.Withdraw(-30m);
            Display += "\nWithdraw -$30, Withdraw: " + withdraw +
                       "\nBalance: " + b1.Balance;

            //// test ApplyMonthlyFee method
            Display += "\n\nBalance Before Monthly Fee: " + b1.Balance;
            decimal monthlyFee = b1.ApplyMonthlyFee();

            Display += "\nFee Charged: " + monthlyFee +
                       "\nNew Balance: " + b1.Balance;

            //// test overdraft mode
            Display += "\n\nOverdraft Mode: Withdraw $100";
            withdraw = b1.Withdraw(100m);
            Display += "\nAmount Withdrawn: " + withdraw +
                       "\nBalance: " + b1.Balance;
            withdraw = b1.Withdraw(500m);
            Display += "\nWithdraw Past Overdraft: Withdraw $500" +
                       "\nAmount Withdrawn: " + withdraw +
                       "\nBalance: " + b1.Balance;

            MessageBox.Show(Display, BankAccount.BankName);
        }