Facebook
From jas, 2 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 87
  1. using System;
  2.  
  3. namespace Assignment_1B
  4. {
  5.     public class Account
  6.     {
  7.         // To do - declare all class data members as properties (ID, Name and Value
  8.         public int ID { get; set; }
  9.         public string Name { get; set; }
  10.         public double Value { get; set; } = 0.0;
  11.  
  12.  
  13.         public virtual void Deposit(double amount)
  14.         {
  15.             Value += amount;
  16.         }
  17.         public virtual void Withdraw(double amount)
  18.         {
  19.              Value -= amount;
  20.         }
  21.     }
  22.  
  23.     public class SavingsAccount : Account
  24.     {
  25.         public double InterestRate { get; set; }
  26.  
  27.         public void MonthEnd()
  28.         {
  29.             Value += Value * InterestRate;
  30.         }
  31.     }
  32.  
  33.     public class CheckingAccount : Account
  34.     {
  35.         public int TransactionLimit { get; set; }
  36.         public int TransactionCount { get; private set; }
  37.         public double TransactionFee { get; set; }
  38.         public double AccountFee { get; set; }
  39.  
  40.         public override void Deposit(double amount)
  41.         {
  42.             Value += amount;
  43.         }
  44.  
  45.         public override void Withdraw(double amount)
  46.         {
  47.             Value -= amount;
  48.         }
  49.  
  50.         private void UpdateTransectionCount()
  51.         {
  52.             Value = TransactionLimit - TransactionCount;
  53.         }
  54.  
  55.         public void MonthEnd()
  56.         {
  57.            
  58.             Value = Value - ((TransactionLimit * TransactionFee)+AccountFee);
  59.         }
  60.     }
  61.     class Program
  62.     {
  63.         static void Main(string[] args)
  64.         {
  65.             var mySavingsAccount = new SavingsAccount { ID = 5, Name = "My Savings Account", InterestRate = 0.01 };
  66.             mySavingsAccount.Deposit(100.0);
  67.             mySavingsAccount.Withdraw(20.0);
  68.             Console.WriteLine("Current Balance after all transections (Savings Account): " + mySavingsAccount.Value);
  69.             mySavingsAccount.MonthEnd();
  70.             Console.WriteLine("Balance after month end (Savings Account): " + mySavingsAccount.Value);
  71.  
  72.  
  73.             var myCheckingAccount = new CheckingAccount { ID = 7, Name = "My Checking Account", TransactionLimit = 2, TransactionFee = 1.5, AccountFee = 5.0 };
  74.             myCheckingAccount.Deposit(100.0);
  75.             myCheckingAccount.Withdraw(10.0);
  76.             myCheckingAccount.Withdraw(10.0);
  77.             myCheckingAccount.Withdraw(10.0);
  78.             myCheckingAccount.Deposit(100.0);
  79.             myCheckingAccount.Withdraw(20.0);
  80.             Console.WriteLine("Current Balance after all transections (Checking Account): " + myCheckingAccount.Value);
  81.             myCheckingAccount.MonthEnd();
  82.             Console.WriteLine("Balance after month end (Checking Account):" + myCheckingAccount.Value);
  83.         }
  84.     }
  85.  
  86. }
  87.