-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSavingsAccount.cs
61 lines (52 loc) · 1.77 KB
/
SavingsAccount.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bank
{
class SavingsAccount:UniversalAccount
{
protected double interest_rate; //annual interest rate
protected DateTime paymentDate; //date of last percents' payment
public SavingsAccount(int number, string password, double balance, double rate, DateTime openDate)
{
this.number = number;
this.password = password;
this.balance = balance;
this.interest_rate = rate;
this.openDate = openDate;
this.paymentDate = openDate;
}
public SavingsAccount()
{ }
public override double CheckBalance(DateTime currentDate)
{
double currentBalance = this.balance;
int months = CountMonths(currentDate, paymentDate);
for (int i = 0; i < months; i++)
currentBalance *= (1 + interest_rate / 100 / 12);
return currentBalance;
}
public override void PutMoney(double sum, DateTime currentDate)
{
balance = CheckBalance(currentDate);
paymentDate = new DateTime(currentDate.Year, currentDate.Month, openDate.Day);
balance += sum;
}
public override double WithdrawMoney(double sum, DateTime currentDate)
{
this.balance = CheckBalance(currentDate);
paymentDate = new DateTime(currentDate.Year, currentDate.Month, openDate.Day);
if (balance >= sum)
{
balance -= sum;
return sum;
}
else
{
Console.WriteLine("Not enough money");
return 0;
}
}
}
}