Skip to content

Commit 2299516

Browse files
author
coursar
committed
feat(methods)
1 parent d4f0b58 commit 2299516

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

methods/src/BonusService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class BonusService {
2+
public long calculate(long amount, boolean registered) {
3+
int percent = registered ? 3 : 1;
4+
long bonus = amount * percent / 100 / 100;
5+
long limit = 500;
6+
if (bonus > limit) {
7+
bonus = limit;
8+
}
9+
return bonus;
10+
}
11+
}
12+
13+

methods/src/Main.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class Main {
2+
public static void main(String[] args) {
3+
BonusService service = new BonusService();
4+
5+
long bonusBelowLimitForRegistered = service.calculate(1000_60, true);
6+
System.out.println(bonusBelowLimitForRegistered);
7+
8+
long bonusOverLimitForRegistered = service.calculate(1_000_000_60, true);
9+
System.out.println(bonusOverLimitForRegistered);
10+
11+
long bonusBelowLimitForUnRegistered = service.calculate(1000_60, false);
12+
System.out.println(bonusBelowLimitForUnRegistered);
13+
14+
long bonusOverLimitForUnRegistered = service.calculate(1_000_000_60, true);
15+
System.out.println(bonusOverLimitForUnRegistered);
16+
}
17+
}
18+

0 commit comments

Comments
 (0)