Inheritance: IAccount
Beispiel #1
0
        public ATM(Account a)
        {
            Console.WriteLine("Welcome to C# ATM Service!\n");

            _account = a;
            _commandManager = new CommandManager(a);
        }
        public void TestProcessMonthlyInterest()
        {
            TestSnapShotDailyBalance();
            InterestController interestController = new InterestController();
            double interestRate = interestController.GetInterestRate(_unitUnderTest);
            _unitUnderTest.ProcessMonthlyInterest(interestRate);
            Assert.AreEqual(105 + ((150.0 + 105.0) / 2 * interestRate) /*108.1875*/, _unitUnderTest.GetBalance());

            Account oldAccount = new Account(150, new DateTime(DateTime.Now.AddYears(-7).Ticks));
            oldAccount.SnapShotDailyBalance();
            oldAccount.Withdraw(45);
            oldAccount.SnapShotDailyBalance();
            interestRate = interestController.GetInterestRate(oldAccount);
            oldAccount.ProcessMonthlyInterest(interestRate);
            Assert.AreEqual(105 + ((150.0 + 105.0) / 2 * interestRate), oldAccount.GetBalance());

            Account newAccountWHighBalance = new Account(70000);
            newAccountWHighBalance.SnapShotDailyBalance();
            newAccountWHighBalance.Deposit(60000);
            newAccountWHighBalance.SnapShotDailyBalance();
            interestRate = interestController.GetInterestRate(newAccountWHighBalance);
            newAccountWHighBalance.ProcessMonthlyInterest(interestRate);
            Assert.AreEqual(130000 + ((70000.0 + 130000.0) / 2 * interestRate) /*132500*/, newAccountWHighBalance.GetBalance());

            Account oldAccountWHighBalance =
                new Account(70000, new DateTime(DateTime.Now.AddYears(-7).Ticks));
            oldAccountWHighBalance.SnapShotDailyBalance();
            oldAccountWHighBalance.Deposit(60000);
            oldAccountWHighBalance.SnapShotDailyBalance();
            interestRate = interestController.GetInterestRate(oldAccountWHighBalance);
            oldAccountWHighBalance.ProcessMonthlyInterest(interestRate);
            Assert.AreEqual(130000 + ((70000.0 + 130000.0) / 2 * interestRate), oldAccountWHighBalance.GetBalance());
        }
        public decimal PayBill(string billCode, Account payer, decimal payment)
        {
            payer.TransferFunds(utilitiesAccount, payment);
            this.bills[billCode] -= payment;

            return this.bills[billCode];
        }
Beispiel #4
0
		public void Init()
		{
			source = new Account();
			source.Deposit(200m);

			destination = new Account();
			destination.Deposit(150m);
		}
Beispiel #5
0
        public virtual void TransferFunds(Account destination, decimal amount)
        {
            if(this.Balance < amount)
            {
                throw new InsufficientFundsException("A ${0:0.00} transfer was requested, but the source account did not have enough balance.");
            }

            this.Balance -= amount;
            destination.Balance += amount;
        }
 public double GetInterestRate(Account account)
 {
     double interestRate = 0.025;
     double highInterestRate = interestRate + 0.005;
     int thresholdBalance = 50000;
     int thresholdDays = 365*5;
     bool isEligibleForHigherRate = account.GetAverageDailyBalance() > thresholdBalance
                                    && (DateTime.Now - account.CreatedDate).Days > thresholdDays;
     return isEligibleForHigherRate ? highInterestRate : interestRate;
 }
 public int AddCustomer(Customer iCustomer)
 {
     ValidateLastName(iCustomer);
     ValidateFirstName(iCustomer);
     ValidatePhoneNumber(iCustomer);
     ValidateAge(iCustomer);
     Account account = new Account();
     iCustomer.BankAccount = account;
     customers.Add(iCustomer);
     return iCustomer.BankAccount.AccountNumber;
 }
Beispiel #8
0
        public bool Transfer(Account a, Money amount)
        {
            if (_balance < amount)
            {
                throw new InsufficientFundsException();
            }

            if (amount.Amount < 0)
            {
                throw new InvalidAmountException();
            }

            // Remove balance from this account
            _balance = _balance - amount;

            // Add balance to Account a
            a._balance = a._balance + amount;

            return true;
        }
Beispiel #9
0
        public static Account GetAccount(int cardNumber)
        {
            Account account = new Account();

            SqlConnection myConnection = getConnection();
            SqlDataReader myReader = null;
            SqlCommand cmd = new SqlCommand();

            try
            {
                myConnection.Open();
                cmd.Connection = myConnection;
                cmd.CommandText = "sp_getAccount";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Clear();

                cmd.Parameters.Add(new SqlParameter("@CardNumber", cardNumber));

                myReader = cmd.ExecuteReader();
                myReader.Read();
                account.AccountNumber = Convert.ToInt32(myReader["AccountNumber"]);
                account.Balance = Convert.ToDecimal(myReader["Balance"]);
                account.WithdrawalLimitPerDay = Convert.ToDecimal(myReader["WithdrawalLimitPerDay"]);
                account.WithdrawalLimitPerTime = Convert.ToDecimal(myReader["WithdrawalLimitPerTime"]);
            }
            catch (Exception)
            {
                throw new CustomException("Ogiltigt kort. Kontakta ditt bankkontor.");
            }
            finally
            {
                myConnection.Close();
            }

            return account;
        }
    private static void OpenNegativeTest()
    {
      var account = new Account(-99, true, 100);

    }
Beispiel #11
0
 public static void PrintInterest(Account acc, decimal months = 6)
 {
     Console.WriteLine("{0} \r\nInterest after {1} months: {2}", acc, months, acc.GetInterest(months).ToString("C"));
 }
 public UtilitiesPaymentProcessor(Account utilitiesAccount)
 {
     this.utilitiesAccount = utilitiesAccount;
 }
Beispiel #13
0
 public static Ice.DispatchStatus getAccountNumber___(Account obj__, IceInternal.Incoming inS__, Ice.Current current__)
 {
     checkMode__(Ice.OperationMode.Normal, current__.mode);
     inS__.readEmptyParams();
     string ret__ = obj__.getAccountNumber(current__);
     IceInternal.BasicStream os__ = inS__.startWriteParams__(Ice.FormatType.DefaultFormat);
     os__.writeString(ret__);
     inS__.endWriteParams__(true);
     return Ice.DispatchStatus.DispatchOK;
 }
Beispiel #14
0
 public void RemoveAccount(Account acc)
 {
     this.accounts.Remove(acc);
 }
Beispiel #15
0
 public static Ice.DispatchStatus transfer___(Account obj__, IceInternal.Incoming inS__, Ice.Current current__)
 {
     checkMode__(Ice.OperationMode.Normal, current__.mode);
     IceInternal.BasicStream is__ = inS__.startReadParams();
     string accountNumber;
     int amount;
     accountNumber = is__.readString();
     amount = is__.readInt();
     inS__.endReadParams();
     try
     {
         obj__.transfer(accountNumber, amount, current__);
         inS__.writeEmptyParams__();
         return Ice.DispatchStatus.DispatchOK;
     }
     catch(Bank.IncorrectAccountNumber ex__)
     {
         inS__.writeUserException__(ex__, Ice.FormatType.DefaultFormat);
         return Ice.DispatchStatus.DispatchUserException;
     }
     catch(Bank.IncorrectAmount ex__)
     {
         inS__.writeUserException__(ex__, Ice.FormatType.DefaultFormat);
         return Ice.DispatchStatus.DispatchUserException;
     }
 }
 public void SetUp()
 {
     _unitUnderTest = new Account(100);
 }
 private static void OpenNegativeBig()
 {
   var account = new Account(-2000, true, 5000);
 }
 public void TearDown()
 {
     _unitUnderTest = null;
 }
    private static void WithdrawTest()
    {
      var account = new Account(0, true, 1);

      account.Withdraw(1);
    }
Beispiel #20
0
 private static void PrintAccount(string text, Account account, int months)
 {
     Console.ForegroundColor = ConsoleColor.White;
     Console.WriteLine(text);
     Console.ResetColor();
     Console.WriteLine(account);
     Console.WriteLine("Interest amount: " + account.InterestAmount(months));
     Console.WriteLine();
 }
Beispiel #21
0
 public void AddAccount(Account acc)
 {
     this.accounts.Add(acc);
 }