Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //
            // Create the Checking Account with initial balance
            CheckingAcc checking = new CheckingAcc("Ahmad", "Nasser", 2500.0m);
            // Create the Savings Account with interest and initial balance
            SavingsAcc saving = new SavingsAcc("Ahmad", "Nasser", 1000.0m);

            // Check the balances
            // Expected output should be 2500 and 1000 at this point
            Console.WriteLine($"Checking balance is {checking.Balance:C2}");
            Console.WriteLine($"Savings balance is {saving.Balance:C2}");
            // Print the account owner information. Expected output:
            // "Checking owner: Ahmad Nasser"
            // "Savings owner: Ahmad Nasser"
            Console.WriteLine($"Checking owner: {checking.AccountOwner}");
            Console.WriteLine($"Savings owner: {saving.AccountOwner}");
            // Deposit some money in each account
            checking.Deposite(200.0m);
            saving.Deposite(150.0m);
            // Check the balances
            // Expected output should be 2700 and 1150 at this point
            Console.WriteLine($"Checking balance is {checking.Balance:C2}");
            Console.WriteLine($"Savings balance is {saving.Balance:C2}");
            // Make some withdrawals from each account
            checking.Withdraw(50.0m);
            saving.Withdraw(125.0m);
            // Check the balances
            // Expected output should be 2650 and 1025 at this point
            Console.WriteLine($"Checking balance is {checking.Balance:C2}");
            Console.WriteLine($"Savings balance is {saving.Balance:C2}");
            // More than 3 Savings withdrawals should result in 2.00 charge
            saving.Withdraw(10.0m);
            saving.Withdraw(20.0m);
            saving.Withdraw(30.0m);
            // Savings balance should now be 988.63
            Console.WriteLine($"Savings balance is {saving.Balance:C2}");
            // try to overdraw savings - this should be denied and print message
            saving.Withdraw(2000.0m);
            // try to overdraw checking - this should be denied and print message
            checking.Withdraw(3000.0m);
            Console.WriteLine($"Checking balance is {checking.Balance:C2}");
            Console.WriteLine($"Savings balance is {saving.Balance:C2}");
        }
Ejemplo n.º 2
0
        private void saveBtn_Click(object sender, EventArgs e)
        {
            string errorText         = "";
            bool   hasFormInputError = false;

            if (FormValidation.IsEmpty(accHolderNameTxtBox.Text, "Name"))
            {
                errorText        += FormValidation.ErrorText + "\n";
                hasFormInputError = true;
            }

            if (FormValidation.IsEmpty(locationTxtbox.Text, "Location"))
            {
                errorText        += FormValidation.ErrorText + "\n";
                hasFormInputError = true;
            }
            if (FormValidation.IsEmpty(checkingAccNoTxtBox.Text, "Checkin Account No"))
            {
                errorText        += FormValidation.ErrorText + "\n";
                hasFormInputError = true;
            }
            if (!FormValidation.IsPositiveValue(checkingAccNoTxtBox.Text))
            {
                errorText        += FormValidation.ErrorText + " for checking acc no!\n";
                hasFormInputError = true;
            }
            if (!FormValidation.IsDouble(checkingAccBalanceTxtBox.Text))
            {
                errorText        += FormValidation.ErrorText + " for chekcing balance\n";
                hasFormInputError = true;
            }
            if (FormValidation.IsEmpty(savingsAccNoTxtBox.Text, "Savings Account No"))
            {
                errorText        += FormValidation.ErrorText + "\n";
                hasFormInputError = true;
            }
            if (!FormValidation.IsPositiveValue(savingsAccNoTxtBox.Text))
            {
                errorText        += FormValidation.ErrorText + " for savings acc no!\n";
                hasFormInputError = true;
            }
            if (!FormValidation.IsDouble(savingAccBalanceTxtBox.Text))
            {
                errorText        += FormValidation.ErrorText + " for savings balance\n";
                hasFormInputError = true;
            }

            if (hasFormInputError)
            {
                showBtn.Visible = false;
                MessageBox.Show("Please fix the following error\n\n" + errorText, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                CheckingAcc aCheckingAcc = new CheckingAcc(Double.Parse(checkingAccBalanceTxtBox.Text), accHolderNameTxtBox.Text, locationTxtbox.Text, Int32.Parse(checkingAccNoTxtBox.Text));
                SavingsAcc  aSavingsAcc  = new SavingsAcc(Double.Parse(savingAccBalanceTxtBox.Text), accHolderNameTxtBox.Text, locationTxtbox.Text, Int32.Parse(savingsAccNoTxtBox.Text));
                accountSummary  = aCheckingAcc.ToString() + aSavingsAcc.ToString();
                showBtn.Visible = true;
                MessageBox.Show("Information saved successfully!", "", MessageBoxButtons.OK);
            }
        }