A
A
Amir Kenesbay2021-01-28 01:43:52
Java
Amir Kenesbay, 2021-01-28 01:43:52

Create multiple accounts and calculate taxes for them?

There is a class Bill , in which the field TaxType taxType is added; and the payTaxes() method :

public class Bill {
    private double amount;
    private TaxType taxType;
    private TaxService taxService;

    public Bill(double amount, TaxType taxType, TaxService taxService){
        this.amount = amount;
        this.taxType = taxType;
        this.taxService = taxService;
    }

    public void payTaxes(){
        //TODO вместо 0.0 посчитать размер налога исходя из TaxType
        double taxAmount = 0.0;
        taxService.payOut(taxAmount);
    }
}


As well as the tax service class:

public class TaxService {
    public void payOut(double taxAmount){
        System.out.format("Уплачен налог в размере %.2f%n", taxAmount);
    }
}


Well, the base class for various types of taxation:
public class TaxType {
    public double calculateTaxFor(double amount){
        //TODO override me!
        return 0.0;
    }
}


And there should be classes that extend TaxType :

Income tax, = 13% ( IncomeTaxType )
VAT, = 18% ( VATaxType )
Progressive tax, up to 100 thousand = 10%, more than 100 thousand = 15% ( ProgressiveTaxType )

And the main method :
public class BillMain {
    public static void main(String[] args) {
        TaxService taxService = new TaxService();
        TaxType taxType = new TaxType();
        Bill[] payments = new Bill[]{
                //TODO создать платежи с различными типами налогооблажения
        };

        for (int i = 0; i < payments.length; i++) {
            Bill bill = payments[i];
            bill.payTaxes();
        }
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question