feat(03-tax-calculator): Добавлено задание

This commit is contained in:
Mark Zheleznyakov
2024-11-07 11:39:05 +03:00
parent 45fff6617b
commit fd75d47189
17 changed files with 557 additions and 0 deletions

View File

@ -0,0 +1,43 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.10.2/userguide/building_java_projects.html in the Gradle documentation.
*/
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
application
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
// This dependency is used by the application.
implementation(libs.guava)
}
// Apply a specific Java toolchain to ease working on different environments.
java {
toolchain {
languageVersion = JavaLanguageVersion.of(23)
}
}
application {
// Define the main class for the application.
mainClass = "ru.mrqiz.taxes.App"
}
tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
tasks.named<JavaExec>("run") {
standardInput = System.`in`
}

View File

@ -0,0 +1,10 @@
package ru.mrqiz.taxes;
public class App {
public static void main(String[] args) {
TaxCalculator calc = new TaxCalculator();
System.out.println(calc.calculateTax("Физ", 100000.0)); // 13%
System.out.println(calc.calculateTax("ИП", 1000000.0)); // 15%
System.out.println(calc.calculateTax("Сам", 10.0)); // 6%
}
}

View File

@ -0,0 +1,7 @@
package ru.mrqiz.taxes;
public interface Calculator {
public double calculateTax(Double amount);
}

View File

@ -0,0 +1,12 @@
package ru.mrqiz.taxes;
public class Main {
public static void main(String[] args) {
TaxCalculator calc = new TaxCalculator();
System.out.println(calc.calculateTax("Физ", 100000.0)); // 13%
System.out.println(calc.calculateTax("ИП", 1000000.0)); // 15%
System.out.println(calc.calculateTax("Сам", 10.0)); // 6%
}
}

View File

@ -0,0 +1,25 @@
package ru.mrqiz.taxes;
public class TaxCalculator {
private Calculator getCalculatorByType(String type) {
switch (type) {
case "Физ" -> {
return new TaxPhysCalculator();
}
case "ИП" -> {
return new TaxIndEntCalculator();
}
case "Сам" -> {
return new TaxSelfCalculator();
}
default -> throw new AssertionError();
}
}
public double calculateTax(String type, Double amount) {
Calculator c = this.getCalculatorByType(type);
return c.calculateTax(amount);
};
}

View File

@ -0,0 +1,10 @@
package ru.mrqiz.taxes;
public class TaxIndEntCalculator implements Calculator {
@Override
public double calculateTax(Double amount) {
return amount * 0.15;
};
}

View File

@ -0,0 +1,10 @@
package ru.mrqiz.taxes;
public class TaxPhysCalculator implements Calculator {
@Override
public double calculateTax(Double amount) {
return amount * 0.13;
};
}

View File

@ -0,0 +1,10 @@
package ru.mrqiz.taxes;
public class TaxSelfCalculator implements Calculator {
@Override
public double calculateTax(Double amount) {
return amount * 0.06;
};
}