/
kai_mai
/
PolymorphismTaxSystem
Обзор
Документация
Войти
/
kai_mai
/
PolymorphismTaxSystem
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Company.java
51 строка
1 KB
Катя Майборода
upload files
04 ноя 2025, 17:22
04 ноя 2025, 17:22
d8c6b82
Код
Авторство
О чём код?
import taxes.TaxSystem; public class Company { // Логика контроля доходов и расходов private String title; // название private int debit; // доходы private int credit; // расходы private TaxSystem taxSystem; public Company(String title, TaxSystem taxSystem) { // конструктор this.title = title; this.taxSystem = taxSystem; this.debit = 0; this.credit = 0; } public void shiftMoney(int amount) { if (amount > 0) { debit += amount; } else if (amount < 0) { credit += Math.abs(amount); } } public void setTaxSystem(TaxSystem taxSystem) { this.taxSystem = taxSystem; } public void payTaxes() { int tax = taxSystem.calcTaxFor(debit, credit); System.out.printf("Компания %s уплатила налог в размере: %d руб.\n", title, tax); debit = 0; credit = 0; } public int applyDeals(Deal[] deals) { int initialDebit = this.debit; int initialCredit = this.credit; for (Deal deal : deals) { this.debit += deal.debitChange; this.credit += deal.creditChange; } int profitBeforeTax = this.debit - this.credit; payTaxes(); return profitBeforeTax; } }