feat(03-tax-calculator): Добавлено задание
This commit is contained in:
43
labs/03-tax-calculator/app/build.gradle.kts
Normal file
43
labs/03-tax-calculator/app/build.gradle.kts
Normal 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`
|
||||
}
|
||||
|
||||
@ -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%
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package ru.mrqiz.taxes;
|
||||
|
||||
public interface Calculator {
|
||||
|
||||
public double calculateTax(Double amount);
|
||||
|
||||
}
|
||||
@ -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%
|
||||
}
|
||||
|
||||
}
|
||||
@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package ru.mrqiz.taxes;
|
||||
|
||||
public class TaxIndEntCalculator implements Calculator {
|
||||
|
||||
@Override
|
||||
public double calculateTax(Double amount) {
|
||||
return amount * 0.15;
|
||||
};
|
||||
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package ru.mrqiz.taxes;
|
||||
|
||||
public class TaxPhysCalculator implements Calculator {
|
||||
|
||||
@Override
|
||||
public double calculateTax(Double amount) {
|
||||
return amount * 0.13;
|
||||
};
|
||||
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package ru.mrqiz.taxes;
|
||||
|
||||
public class TaxSelfCalculator implements Calculator {
|
||||
|
||||
@Override
|
||||
public double calculateTax(Double amount) {
|
||||
return amount * 0.06;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user