Example #1
0
        static void Main(string[] args)
        {
            Account[] listOf5Accounts = new Account[5];

            SavingsAccount account0 = new SavingsAccount(500, .05);
            CheckingAccount account1 = new CheckingAccount(400, 2);
            CheckingAccount account2 = new CheckingAccount(1000, 2);
            SavingsAccount account3 = new SavingsAccount(200, .035);
            CheckingAccount account4 = new CheckingAccount(750, 2);

            listOf5Accounts[0] = account0;
            listOf5Accounts[1] = account1;
            listOf5Accounts[2] = account2;
            listOf5Accounts[3] = account3;
            listOf5Accounts[4] = account4;

            Console.WriteLine("This program lets the user enter info for 5 accounts.\nPlease specify the amount to credit and debit for each account.\n");

            // This section of code gets user input for credits and debits and displays all account info accordingly.
            // Each method below is a public static void method located in class Account.
            Account.DisplayAccountInfo(listOf5Accounts);
            Account.DisplayInterest(listOf5Accounts);

            Account.GetUserCreditsAndDebits(listOf5Accounts);

            Account.DisplayInterest(listOf5Accounts);
            Account.CreditInterest(listOf5Accounts);

            Account.DisplayAccountInfo(listOf5Accounts);
        }
Example #2
0
 // These methods manipulate the information given by the user and edit an array of account objects as an argument to each method
 public static void DisplayAccountInfo(Account[] listOfAccounts)
 {
     // Display all account info.
     displayStar();
     int accountNumber = 1;
     foreach (var account in listOfAccounts)
     {
         Console.WriteLine("\tThe current balance of Account {0} is {1:C}", accountNumber, account.Balance);
         Console.WriteLine("\tAccount {0} is of type {1}\n", accountNumber, account.GetType().Name);
         accountNumber++;
     }
     displayStar();
 }
Example #3
0
 public static void CreditInterest(Account[] listOfAccounts)
 {
     displayStar();
     Console.WriteLine("\n\tThe calculated interest is now being added to each savings account.\n");
     int accountNumber = 1;
     foreach (var account in listOfAccounts)
     {
         if(account is SavingsAccount)
         {
             (account as SavingsAccount).Credit((account as SavingsAccount).CalculateInterest());
         }
         accountNumber++;
     }
     displayStar();
 }
Example #4
0
 public static void DisplayInterest(Account[] listOfAccounts)
 {
     displayStar();
     int accountNumber = 1;
     foreach (var account in listOfAccounts)
     {
         if (account is SavingsAccount)
         {
             Console.WriteLine("\n\tThe current calculated interest of account {0} is {1:C}\n", accountNumber, (account as SavingsAccount).CalculateInterest());
         }
         accountNumber++;
     }
     displayStar();
 }
Example #5
0
        public static void GetUserCreditsAndDebits(Account[] listOfAccounts)
        {
            displayStar();
            // Get user input for credit and debits.
            int accountNumber = 1;
            foreach (var account in listOfAccounts)
            {
                displayAt();

                Console.WriteLine("\n\tPlease enter the amount of money you want to deposit into Account {0}.\n\tThe current balance is {1:C}\n", accountNumber, account.Balance);
                try
                {
                    Console.Write("\t");
                    account.Credit(Convert.ToDecimal(Console.ReadLine()));
                }
                catch (FormatException)
                {

                }
                Console.WriteLine("\n\tThe new balance is {0:C}\n", account.Balance);

                displayAt();

                Console.WriteLine("\n\tPlease enter the amount of money you want to withdraw from Account {0}.\n\tThe current balance is {1:C}\n", accountNumber, account.Balance);
                try
                {
                    Console.Write("\t");
                    account.Debit(Convert.ToDecimal(Console.ReadLine()));
                }
                catch (FormatException)
                {

                }
                Console.WriteLine("\n\tThe new balance is {0:C}\n", account.Balance);

                accountNumber++;

                displayAt();
            }

            displayStar();
        }