Skip to content

Instantly share code, notes, and snippets.

@kingseungil
Last active August 2, 2023 04:37
Show Gist options
  • Save kingseungil/c614c2c547541a6577c4c25dd8d9943f to your computer and use it in GitHub Desktop.
Save kingseungil/c614c2c547541a6577c4c25dd8d9943f to your computer and use it in GitHub Desktop.
Zerobase-miniproject
import java.util.Scanner;
public class Miniproject8 {
// Enum으로 상수 정의
public enum IncomeLevel {
LEVEL_1(0, 12000000, 6, 0),
LEVEL_2(12000000, 46000000, 15, 1080000),
LEVEL_3(46000000, 88000000, 24, 5220000),
LEVEL_4(88000000, 150000000, 35, 14900000),
LEVEL_5(150000000, 300000000, 38, 19400000),
LEVEL_6(300000000, 500000000, 40, 25400000),
LEVEL_7(500000000, 1000000000, 42, 35400000),
LEVEL_8(1000000000, Long.MAX_VALUE, 45, 65400000);
private final long minIncome;
private final long maxIncome;
private final long taxRate;
private final long deduction;
IncomeLevel(long minIncome, long maxIncome, long taxRate, long deduction) {
this.minIncome = minIncome;
this.maxIncome = maxIncome;
this.taxRate = taxRate;
this.deduction = deduction;
}
public long getMinIncome() {
return minIncome;
}
public long getMaxIncome() {
return maxIncome;
}
public long getTaxRate() {
return taxRate;
}
public long getDeduction() {
return deduction;
}
}
// 입력부분(연소득 받아오기)
public static long input() {
long annual_income;
try(Scanner sc = new Scanner(System.in)) {
System.out.println("[과세금액 계산 프로그램]");
while (true) {
System.out.print("연소득을 입력해 주세요.:");
annual_income = sc.nextLong();
// 예외부분처리
if (annual_income < 0) {
System.out.print("다시 입력해주세요.");
continue;
}
break;
}
return annual_income;
}
}
// 누진공제 계산
public static long Deduction(long annual_income,int idx){
return (annual_income * IncomeLevel.values()[idx].getTaxRate() / 100) - IncomeLevel.values()[idx].getDeduction();
}
public static void main(String[] args) {
long annual_income = input();
int idx = -1; // 인덱스설정
long totaltax = 0;
//세금계산
for (IncomeLevel level : IncomeLevel.values()) {
idx++;
if (annual_income > level.getMaxIncome()) { // Enum 값 사용
long tax = (level.getMaxIncome() - level.getMinIncome()) * level.getTaxRate() / 100;
System.out.printf("%,15d * %2d%% = %,12d \n", (level.getMaxIncome() - level.getMinIncome()), level.getTaxRate(), tax);
totaltax += tax;
} else {
long tax = (annual_income - level.getMinIncome()) * level.getTaxRate() / 100;
System.out.printf("%,15d * %2d%% = %,12d \n", (annual_income - level.getMinIncome()), level.getTaxRate(), tax);
totaltax += tax;
break;
}
}
System.out.println();
System.out.printf("[세율에 의한 세금]: \t\t\t\t\t %,12d\n",totaltax);
System.out.printf("[누진공제 계산에 의한 세금]: \t %,12d",Deduction(annual_income,idx));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment