-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.cpp
More file actions
173 lines (135 loc) · 6.88 KB
/
Copy pathBank.cpp
File metadata and controls
173 lines (135 loc) · 6.88 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Dawid Bartosiak
#include <iostream>
#include <algorithm>
#include "Bank.h"
const int bankCreditworthiness = 99999999;
class Bank;
Bank::Bank(const double& aInterestRate) {
if (aInterestRate <= 0 )
{ throw std::out_of_range("Interest rate cannot be negative."); }
else { interestRate = aInterestRate; }
}
FixedInstallmentLoan BankBranchFixed::give_loan(std::shared_ptr<Bank> bank, std::shared_ptr<Person> person, const double& amount,
const unsigned int& ratesAmount, const unsigned int& ratesInYear, const double& creditworthiness) {
if (amount <= 0 || ratesAmount <= 0 || ratesInYear <= 0 )
{ throw std::out_of_range("Any of loan parameter cannot be negative."); }
FixedInstallmentLoan loan = FixedInstallmentLoan(Authorisation(), amount, this->interestRate, ratesAmount, ratesInYear, creditworthiness);
if (std::find(people.begin(), people.end(), person) != people.end()) { return loan; }
else {
bank->add_person(Authorisation(), person);
return loan;
}
}
double BankBranchFixed::get_interest_rate() const noexcept{
return interestRate;
}
FixedInstallmentLoan BankBranchFixed::create_loan_fixed(const double& amount, const unsigned int& ratesAmount, const unsigned int& ratesInYear) const {
if (amount <= 0 || ratesAmount <= 0 || ratesInYear <= 0) {
throw std::out_of_range("Any of loan parameter cannot be negative.");
}
FixedInstallmentLoan loan = FixedInstallmentLoan(Authorisation(), amount, interestRate, ratesAmount, ratesInYear, bankCreditworthiness);
return loan;
}
DescendingInstallmentLoan BankBranchDescending::give_loan(std::shared_ptr<Bank> bank, std::shared_ptr<Person> person, const double& amount,
const unsigned int& ratesAmount, const unsigned int& ratesInYear, const double& creditworthiness) {
if (amount <= 0 || ratesAmount <= 0 || ratesInYear <= 0)
{ throw std::out_of_range("Any of loan parameter cannot be negative."); }
DescendingInstallmentLoan loan = DescendingInstallmentLoan(Authorisation(), amount, interestRate, ratesAmount, ratesInYear, creditworthiness);
if (std::find(people.begin(), people.end(), person) != people.end()) { return loan; }
else {
bank->add_person(Authorisation(), person);
return loan;
}
}
double BankBranchDescending::get_interest_rate() const noexcept{
return interestRate;
}
DescendingInstallmentLoan BankBranchDescending::create_loan_descending(const double& amount, const unsigned int& ratesAmount, const unsigned int& ratesInYear) const {
if (amount <= 0 || ratesAmount <= 0 || ratesInYear <= 0){
throw std::out_of_range("Any of loan parameter cannot be negative.");
}
DescendingInstallmentLoan loan = DescendingInstallmentLoan(Authorisation(), amount, interestRate, ratesAmount, ratesInYear, bankCreditworthiness);
return loan;
}
void BankBranchDescending::overpay_descending(DescendingInstallmentLoan& loan, const double& amount) {
if (amount <= 0)
{ throw std::out_of_range("You can't overpay negative amount of money."); }
else{ loan.overpay(Authorisation(), amount); }
}
void BankBranchFixed::overpay_fixed(FixedInstallmentLoan& loan, const double& amount) {
if (amount <= 0)
{ throw std::out_of_range("You can't overpay negative amount of money."); }
else { loan.overpay(Authorisation(), amount); }
}
double Bank::get_interest_rate() const noexcept { return interestRate; }
FixedInstallmentLoan Bank::create_loan_fixed(const double& amount, const unsigned int& ratesAmount, const unsigned int& ratesInYear) const {
BankBranchFixed fixedBranch = BankBranchFixed(interestRate);
return fixedBranch.create_loan_fixed(amount, ratesAmount, ratesInYear);
}
FixedInstallmentLoan Bank::give_loan_fixed(std::shared_ptr<Person> person, const double& amount,
const unsigned int& ratesAmount, const unsigned int& ratesInYear, const double& creditworthiness){
BankBranchFixed fixedBranch = BankBranchFixed(interestRate);
return fixedBranch.give_loan(get_bank(), person, amount, ratesAmount, ratesInYear, creditworthiness);
}
double Bank::get_fixed_loan_negative_creditworthiness(FixedInstallmentLoan& loan) const noexcept {
BankBranchFixed fixedBranch = BankBranchFixed(interestRate);
return fixedBranch.get_fixed_loan_negative_creditworthiness(loan);
}
void Bank::overpay_fixed(FixedInstallmentLoan& loan, const double& amount){
BankBranchFixed fixedBranch = BankBranchFixed(interestRate);
fixedBranch.overpay_fixed(loan, amount);
}
DescendingInstallmentLoan Bank::create_loan_descending(const double& amount, const unsigned int& ratesAmount, const unsigned int& ratesInYear) const {
BankBranchDescending descendingBranch = BankBranchDescending(interestRate);
return descendingBranch.create_loan_descending(amount, ratesAmount, ratesInYear);
}
DescendingInstallmentLoan Bank::give_loan_descending(std::shared_ptr<Person> person, const double& amount,
const unsigned int& ratesAmount, const unsigned int& ratesInYear, const double& creditworthiness){
BankBranchDescending descendingBranch = BankBranchDescending(interestRate);
return descendingBranch.give_loan(get_bank(), person, amount, ratesAmount, ratesInYear, creditworthiness);
}
double Bank::get_descending_loan_negative_creditworthiness(DescendingInstallmentLoan& loan) const noexcept {
BankBranchDescending descendingBranch = BankBranchDescending(interestRate);
return descendingBranch.get_descending_loan_negative_creditworthiness(loan);
}
void Bank::overpay_descending(DescendingInstallmentLoan& loan, const double& amount) {
BankBranchDescending descendingBranch = BankBranchDescending(interestRate);
descendingBranch.overpay_descending(loan, amount);
}
void Bank::add_person(Authorisation, std::shared_ptr<Person> person) noexcept {
people.push_back(person);
}
Bank::~Bank(){}
void Bank::set_interest_rate(const double& newInterestRate) {
if (newInterestRate <= 0)
{ throw std::out_of_range("Interest rate cannot be negative."); }
else {
interestRate = newInterestRate;
for (unsigned int i = 0; i <= size(people) - 1; ++i) {
Person person = *people.at(i);
if (size(person.get_fixed()) != 0) {
for (unsigned int j = 0; j <= size(person.get_fixed()) - 1; ++j) {
(*people.at(i)).get_fixed().at(j).set_interest_rates(Authorisation(), interestRate);
}
if (size(person.get_descending()) != 0) {
for (unsigned int j = 0; j <= size(person.get_descending()) - 1; ++j) {
(*people.at(i)).get_descending().at(j).set_interest_rates(Authorisation(), interestRate);
}
}
}
else {
if (size(person.get_descending()) != 0) {
for (unsigned int j = 0; j <= size(person.get_descending()) - 1; ++j) {
(*people.at(i)).get_descending().at(j).set_interest_rates(Authorisation(), interestRate);
}
}
}
}
}
}
double BankBranchDescending::get_descending_loan_negative_creditworthiness(DescendingInstallmentLoan& loan) const noexcept {
return loan.get_negative_creditworthiness(Authorisation());
}
double BankBranchFixed::get_fixed_loan_negative_creditworthiness(FixedInstallmentLoan& loan) const noexcept {
return loan.get_negative_creditworthiness(Authorisation());
}