Skip to content

Commit 45ca04d

Browse files
committed
Interest
1 parent 6fc16c6 commit 45ca04d

7 files changed

Lines changed: 100 additions & 23 deletions

File tree

‎.idea/libraries/coreoz_wisp.xml‎

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Bank.iml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
<orderEntry type="library" name="google.code.gson" level="project" />
1111
<orderEntry type="library" name="tools.jackson.dataformat.xml" level="project" />
1212
<orderEntry type="library" name="google.inject.guice" level="project" />
13+
<orderEntry type="library" name="coreoz.wisp" level="project" />
1314
</component>
1415
</module>

‎src/App.java‎

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import accounts.BankAccount;
2-
import accounts.InterestPoint;
32
import accounts.StudentAccount;
43
import accounts.serialization.BankAccountGsonSerializer;
54
import accounts.serialization.BankAccountXmlSerializer;
5+
import accounts.services.BankAccountService;
66
import accounts.services.IBankAccountService;
7+
import com.coreoz.wisp.Scheduler;
8+
import com.coreoz.wisp.schedule.Schedules;
79
import com.google.inject.Inject;
810
import com.google.inject.name.Named;
911
import currency.Currency;
@@ -14,10 +16,14 @@
1416
import transfer.DepositTransferService;
1517
import transfer.TransferTransferService;
1618
import transfer.WithdrawTransferService;
19+
import transfer.services.IntrestsService;
1720
import transfer.services.TransferLoggerService;
1821

19-
public class App {
22+
import java.time.Duration;
2023

24+
public class App {
25+
@Inject
26+
private IntrestsService intrestsService;
2127
@Inject
2228
private AccountOwnerService accountOwnerService;
2329

@@ -94,12 +100,6 @@ public void run() {
94100
System.out.println(bankAccountJsonAll);
95101

96102

97-
for (BankAccount account: bankAccountService.getBankAccounts()){
98-
if (account instanceof InterestPoint) {
99-
((InterestPoint)account).calculateInterest();
100-
}
101-
}
102-
103103
for (BankAccount account: bankAccountService.getBankAccounts()){
104104

105105
if (account instanceof StudentAccount) {
@@ -160,6 +160,32 @@ public void run() {
160160

161161
System.out.println("TRANSACTIONS");
162162
System.out.println(transferLoggerService.getAllTransactions());
163+
/*while(true){
164+
intrestsService.addIntrest();
165+
printBalance(savingAccount);
166+
try {
167+
Thread.sleep(60_000);
168+
} catch (InterruptedException e) {
169+
Thread.currentThread().interrupt();
170+
return;
171+
}
172+
}*/
173+
Scheduler scheduler = new Scheduler();
174+
175+
scheduler.schedule(
176+
"Saving account interest",
177+
() -> {
178+
intrestsService.addInterest();
179+
180+
notifierService.notify("Úrok byl připsán na účet.");
181+
182+
printBalance(savingAccount);
183+
},
184+
Schedules.afterInitialDelay(
185+
Schedules.fixedDelaySchedule(Duration.ofSeconds(60)),
186+
Duration.ZERO
187+
)
188+
);
163189
}
164190

165191
private void printBalance(BankAccount bankAccount) {

‎src/accounts/InterestPoint.java‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎src/accounts/SavingAccount.java‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,9 @@
22

33
import person.AccountOwner;
44

5-
public class SavingAccount extends BankAccount implements InterestPoint {
6-
private static final float INTEREST_RATE = 0.05f;
5+
public class SavingAccount extends BankAccount {
76

87
public SavingAccount(AccountOwner accountOwner, double balance) {
98
super(accountOwner, balance);
109
}
11-
12-
@Override
13-
public void calculateInterest() {
14-
double interest = getBalance() * INTEREST_RATE;
15-
double newBalance = getBalance() + interest;
16-
17-
super.setBalance(newBalance);
18-
}
1910
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package transfer.services;
2+
3+
import accounts.SavingAccount;
4+
5+
public class IntrestCalculatorService {
6+
private static final double INTEREST_RATE = 0.05;
7+
private static final double INTEREST_TAX_RATE = 0.15;
8+
9+
public double calculateInterest(SavingAccount savingAccount) {
10+
double interest = savingAccount.getBalance() * INTEREST_RATE;
11+
double tax = interest * INTEREST_TAX_RATE;
12+
return interest-tax;
13+
}
14+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package transfer.services;
2+
3+
import accounts.BankAccount;
4+
import accounts.SavingAccount;
5+
import accounts.services.IBankAccountService;
6+
import com.google.inject.Inject;
7+
import com.google.inject.name.Named;
8+
import transfer.DepositTransferService;
9+
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
public class IntrestsService {
14+
@Inject
15+
@Named("plain")
16+
private IBankAccountService bankAccountService;
17+
@Inject
18+
private DepositTransferService depositTransferService;
19+
@Inject
20+
private IntrestCalculatorService intrestCalculatorService;
21+
public List<SavingAccount> getSavingAccounts() {
22+
List<BankAccount> bankAccounts = bankAccountService.getBankAccounts();
23+
List<SavingAccount> savingAccounts = new ArrayList<>();
24+
for(BankAccount account: bankAccounts)
25+
{
26+
if (account instanceof SavingAccount savingAccount){
27+
savingAccounts.add(savingAccount);
28+
}
29+
}
30+
return savingAccounts;
31+
}
32+
public void addInterest ()
33+
{
34+
List<SavingAccount> savingAccounts = getSavingAccounts();
35+
for (SavingAccount savingAccount: savingAccounts){
36+
depositTransferService.deposit(savingAccount,intrestCalculatorService.calculateInterest(savingAccount));
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)