/// ------------------------------------------------------------------- /// <summary>This method takes in a checking account and a number and /// preforms an operation using the checking account methods</summary> /// /// <param name="checkingAccount">The checking account object to /// preform the operation on</param> /// /// <param name="currentNumber">The number revived from /// the CheckingAccountMenu that relates to a operation from the /// Checking Account menu.</param> /// ------------------------------------------------------------------- private static void CheckingAccountOperations(CheckingAccount checkingAccount, int currentNumber) { switch (currentNumber) { case 1: Console.Clear(); Console.Write("How much would you like to add to " + "your account: "); checkingAccount.Credit(decimal.Parse(Console.ReadLine())); break; case 2: Console.Clear(); Console.Write("How much would you like to withdraw " + "to your account: "); checkingAccount.Debit(decimal.Parse(Console.ReadLine())); break; case 3: Console.Clear(); Console.WriteLine($"Your account balance " + $"is: {checkingAccount.getBalance()}"); Console.WriteLine(); break; case 4: Console.Clear(); Console.WriteLine(); Console.WriteLine($"The fee " + $"for the account is:" + $" {checkingAccount.Fee}"); Console.WriteLine(); break; case 5: Console.Clear(); Console.WriteLine(); Console.WriteLine("Back to main menu:"); Console.WriteLine(); break; default: Console.WriteLine(); Console.Clear(); Console.WriteLine("Please enter a number between 1-5"); Console.WriteLine(); break; } }
static void Main(string[] args) { List <Account> accounts = new List <Account>(); SavingsAccount savings = new SavingsAccount("1234", 1000.00M); CheckingAccount checking = new CheckingAccount("9876", 0.50M); accounts.Add(savings); accounts.Add(checking); savings.Deposit(500.23M); // End of month....Hit'em with some fees foreach (Account a in accounts) { a.Withdraw(10.00M); Console.WriteLine($"Account {a.AccountNumber} has {a.Balance:C}"); } }
static void Main(string[] args) { // Cannot do this because Account has been marked "abstract" // Account account = new Account("3456"); int bigNumber = 1000000000; byte smallNumber = (byte)bigNumber; SavingsAccount savings = new SavingsAccount("1234", 1000.00M); CheckingAccount checking = new CheckingAccount("9876", 0.50M); // POLYMORPHISM: We are storing subclasses in a collection declared for the superclass List <Account> accounts = new List <Account>() { savings, checking }; // End of month....Hit'em with some fees foreach (Account acct in accounts) { // POLYMORPHISM: the appropriate method gets called based on the *runtime type*, not the *declared type* acct.Withdraw(10.00M); } // Bank-lotto: Add a random amount to each account Random random = new Random(); foreach (Account acct in accounts) { int amount = random.Next(10, 150); acct.Deposit(amount); } // POLYMORPHISM: the method expects an Account, we send it a CheckingAccount savings.TransferTo(150, checking); // POLYMORPHISM: the method expects an Account, we send it a SavingsAccount or CheckingAccount PrintMonthlyStatement(savings); PrintMonthlyStatement(checking); }
static void Main(string[] args) { SavingsAccount savings = new SavingsAccount("1234", 1000.00M); CheckingAccount checking = new CheckingAccount("9876", 0.50M); // POLYMORPHISM: We are storing subclasses in a collection declared for the superclass List <Account> accounts = new List <Account>() { savings, checking }; // End of month....Hit'em with some fees foreach (Account acct in accounts) { // POLYMORPHISM: the appropriate method gets called based on the *runtime type*, not the *declared type* acct.Withdraw(10.00M); } // Bank-lotto: Add a random amount to each account Random random = new Random(); foreach (Account acct in accounts) { int amount = random.Next(10, 150); acct.Deposit(amount); } // TODO 02: Do a Transfer of 100 from savings to checking. What type do we send for toAccount? // POLYMORPHISM: the method expects an Account, we send it a CheckingAccount savings.TransferTo(150, checking); // TODO 05: Print a Monthly Statement for both accounts. What types are we sending in? What type is expected? // POLYMORPHISM: the method expects an Account, we send it a SavingsAccount or CheckingAccount PrintMonthlyStatement(savings); PrintMonthlyStatement(checking); }
/// ------------------------------------------------------------------- /// <summary>This method creates a Checking Account object with user /// entered initial money amount and interest rate.</summary> /// /// <returns>An CheckingAccount object with a initial amount and /// interest rate set by the user. /// </returns> /// ------------------------------------------------------------------- private static CheckingAccount CreateCheckingAccount() { // The checking account to be returned CheckingAccount checkingAccount = null; decimal initalAmount; // Initial money amount for the account decimal feeAmount; // The fee for using the account // A check to make sure the user input is valid. bool passBool = false; while (!passBool) { try { Console.Write("How much currency would you like to have " + "to start the checking account: "); initalAmount = decimal.Parse(Console.ReadLine()); Console.Write("What is the fee for the " + "account: "); feeAmount = decimal.Parse(Console.ReadLine()); checkingAccount = new CheckingAccount(initalAmount, feeAmount); passBool = true; } catch (Exception ex) { Console.Clear(); Console.WriteLine(ex); Console.WriteLine(); } } return checkingAccount; }
//the main method public static void Main() { //Display a welcoming message Console.WriteLine("WELCOME TO THIS BANKING SYSTEM APPLICATION"); Console.WriteLine("---------------------------------------------------------------------"); //give space Console.WriteLine(); decimal Credit, Debit; //initialize the objects for savings account decimal TotalCredit = 00.00M; SavingsAccount savingsaccount = new SavingsAccount(1000.00M, 0.10M); Console.WriteLine("The customer's beginning balance is {0:C}", savingsaccount.Balance); Console.Write("Enter an amount to Deposit into savings account: $"); Credit = Convert.ToDecimal(Console.ReadLine()); savingsaccount.Credit(Credit); //invokes the calculate interest method TotalCredit = savingsaccount.CalculateInterest(); Console.WriteLine("Interest of {0:C}", TotalCredit); //pass the returned interest amount to the object's credit savingsaccount.Credit(TotalCredit); //an amount is withdrawn from the account and a reasonable fee is charged for the transaction made. Console.Write("Enter an amount to Withdraw from savings account: $"); Debit = Convert.ToDecimal(Console.ReadLine()); savingsaccount.Debit(Debit); Console.WriteLine("The new balance is of savings account is {0:C}", savingsaccount.Balance); Console.WriteLine("---------------------------------------------------------------------"); //initializes the object for checking account //Checking account charges fee for every transactions a customer makes CheckingAccount checkingaccount = new CheckingAccount(1000.00M, 2.50M); Console.WriteLine("The customer's initial balance is {0:C}", checkingaccount.Balance); //an amount is deposited to the account and a fee is charged for the transaction made Console.Write("Enter an amount to Deposit into checking account: $"); Credit = Convert.ToDecimal(Console.ReadLine()); checkingaccount.Credit(Credit); Console.WriteLine("The customer's balance after the amount has been deposited with the fee charged is {0:C}", checkingaccount.Balance); //an amount is withdrawn from the account and a reasonable fee is charged for the transaction made. Console.Write("Enter an amount to Withdraw from checking balance: $"); Debit = Convert.ToDecimal(Console.ReadLine()); checkingaccount.Debit(Debit); //After all the customer's transactions the, the ending balance is displayed Console.WriteLine("The customer's balance after all the transactions done stands to be {0:C}", checkingaccount.Balance); Console.WriteLine("---------------------------------------------------------------------"); //array of Account references to SavingsAccount and CheckingAccount objects. PolymorphicBanking [] account = new PolymorphicBanking[2]; account[0] = savingsaccount; account[1] = checkingaccount; foreach (PolymorphicBanking accounts in account) { Console.WriteLine(accounts); //Display accounts Console.WriteLine("Account Balance: {0}\n", accounts.Balance); //Didplay Account Balance } //Range for (int i = 0; i < account.Length; i++) { //Display account type Console.WriteLine("Account {0} is {1}\n", i, account[i].GetType()); } Console.WriteLine("===================================================="); Console.WriteLine("THANK YOU VERY MUCH FOR USING THIS SYSTEM APPLICATION"); Console.WriteLine("HOPE YOU CHOOSE THIS SYSTEM APPLICATION FOR YOUR NEXT TRANSACTIONS"); Console.ReadKey();//exit the program } // end of main mehod