Created
February 1, 2025 14:43
-
-
Save Exom9434/a13a214ac9edefcf78416bbca63e046c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//노재 | |
import java.util.Scanner; | |
public class Main{ | |
static final int[] TAX_BRACKETS = {12000000, 46000000, 88000000, 150000000, 300000000, 500000000, 1000000000}; //과세 구간별 기준 | |
static final double[] TAX_RATES = {0.06, 0.15, 0.24, 0.35, 0.38, 0.40, 0.42, 0.45}; //구간별 세율 | |
static final int[] DEDUCTIONS = {0, 1080000, 5220000, 14900000, 19400000, 25400000, 35400000, 65400000}; //공제액 | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
System.out.print("연소득을 입력해 주세요: "); | |
int income = scanner.nextInt(); | |
scanner.close(); | |
int taxbyrate = calculateTaxRate(income); | |
int taxbydeduction = calculateTaxDeduction(income); | |
System.out.println("[세율에 의한 세금]: " + taxbyrate); | |
System.out.println("[누진공제 계산에 의한 세금]: " + taxbydeduction); | |
} | |
public static int calculateTaxRate(int income) { | |
int taxbyrate = 0; | |
int prevBracket = 0; | |
for (int i = 0; i < 7; i++) { | |
if (income > TAX_BRACKETS[i]) { | |
taxbyrate += (TAX_BRACKETS[i] - prevBracket) * TAX_RATES[i]; | |
prevBracket = TAX_BRACKETS[i]; | |
} else { | |
taxbyrate += (income - prevBracket) * TAX_RATES[i]; | |
break; | |
} | |
} | |
return taxbyrate; | |
} | |
public static int calculateTaxDeduction(int income){ | |
int taxbydeduction = 0; | |
taxbydeduction += (int) (income * TAX_RATES[getBracketIndex(income)] - DEDUCTIONS[getBracketIndex(income)]); | |
return taxbydeduction; | |
} | |
public static int getBracketIndex(int income) { | |
for (int i = 0; i < TAX_BRACKETS.length; i++) { | |
if (income <= TAX_BRACKETS[i]) { | |
return i; | |
} | |
} | |
return TAX_BRACKETS.length; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment