-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
124 lines (92 loc) · 3.72 KB
/
Copy pathMain.java
File metadata and controls
124 lines (92 loc) · 3.72 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
import java.util.Scanner;
public class Main {
public static final int TAX_EARNINGS = 6;
public static final int TAX_EARNINGS_MINUS_SPENDINGS = 15;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int earnings = 0;
int spendings = 0;
while (true) {
printMenu();
String input = scanner.nextLine();
if ("end".equals(input)) {
break;
}
int operation = Integer.parseInt(input);
switch (operation) {
case 1 -> {
System.out.println("Введите сумму дохода:");
earnings += Integer.parseInt(scanner.nextLine());
}
case 2 -> {
System.out.println("Введите сумму расхода:");
spendings += Integer.parseInt(scanner.nextLine());
}
case 3 -> calculateBestTaxSystem(earnings, spendings);
default -> System.out.println("Такой операции нет");
}
}
System.out.println("Программа завершена!");
}
public static void printMenu() {
System.out.println("""
Выберите операцию и введите её номер
(чтобы завершить программу введите end):
1. Добавить новый доход
2. Добавить новый расход
3. Выбрать систему налогообложения
""");
}
public static int calculateTaxEarnings(int earnings) {
return earnings * TAX_EARNINGS / 100;
}
public static int calculateTaxEarningsMinusSpendings(int earnings, int spendings) {
int tax = (earnings - spendings) *
TAX_EARNINGS_MINUS_SPENDINGS / 100;
return Math.max(tax, 0);
}
public static void calculateBestTaxSystem(int earnings, int spendings) {
int taxEarnings =
calculateTaxEarnings(earnings);
int taxEarningsMinusSpendings =
calculateTaxEarningsMinusSpendings(
earnings,
spendings
);
if (taxEarnings < taxEarningsMinusSpendings) {
printResult(
"УСН доходы",
taxEarnings,
taxEarningsMinusSpendings
);
} else if (taxEarningsMinusSpendings < taxEarnings) {
printResult(
"УСН доходы минус расходы",
taxEarningsMinusSpendings,
taxEarnings
);
} else {
System.out.printf("""
Можете выбрать любую систему налогообложения.
Налог составит: %d рублей
%n""", taxEarnings);
}
}
public static void printResult(
String systemName,
int bestTax,
int otherTax
) {
System.out.printf(
"""
Мы советуем вам %s
Ваш налог составит: %d рублей
Налог в другой системе: %d рублей
Экономия: %d рублей
%n""", systemName,
bestTax,
otherTax,
otherTax - bestTax
);
}
}