Last active
July 9, 2023 23:59
-
-
Save dongsub-joung/13285f90ba35a3112bd0015fe410d395 to your computer and use it in GitHub Desktop.
정동섭
This file contains 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.ArrayList; | |
import java.util.Scanner; | |
class TaxRate{ | |
final static int INTEREST1= 6; | |
final static int INTEREST2= 15; | |
final static int INTEREST3= 24; | |
final static int INTEREST4= 35; | |
final static int INTEREST5= 38; | |
final static int INTEREST6= 40; | |
final static int INTEREST7= 42; | |
final static int INTEREST8= 45; | |
static final int[] INTERESTS= new int[]{INTEREST1, INTEREST2, INTEREST3, INTEREST4, INTEREST5, INTEREST6, INTEREST7, INTEREST8}; | |
} | |
class TaxLine{ | |
final static double WON= 1000000; | |
final static double STAGE1= 0; | |
final static double STAGE2= 12 * WON; | |
final static double STAGE3= 46 * WON; | |
final static double STAGE4= 88 * WON; | |
final static double STAGE5= 150 * WON; | |
final static double STAGE6= 300 * WON; | |
final static double STAGE7= 500 * WON; | |
final static double STAGE8= 1000 * WON; | |
static final double[] STAGES= new double[]{STAGE1, STAGE2, STAGE3, STAGE4, STAGE5, STAGE6, STAGE7, STAGE8}; | |
} | |
class Progressive{ | |
final static long WON= 10000; | |
final static long STAGE1= 0; | |
final static long STAGE2= 108 * WON; | |
final static long STAGE3= 522 * WON; | |
final static long STAGE4= 1490 * WON; | |
final static long STAGE5= 1940 * WON; | |
final static long STAGE6= 2540 * WON; | |
final static long STAGE7= 3540 * WON; | |
final static long STAGE8= 6540 * WON; | |
static final long[] STAGES= new long[]{STAGE1, STAGE2, STAGE3, STAGE4, STAGE5, STAGE6, STAGE7, STAGE8}; | |
} | |
public class Tax { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
// 연소득 금액 입력 | |
System.out.println("[과세금액 계산 프로그램]"); | |
System.out.print("연소득을 입력해 주세요.:"); | |
long income = scanner.nextLong(); | |
// long income= 15000000; | |
// long income= 20000000; | |
// long income= 48000000; | |
// long income= 92000000; | |
// long income= 192000000; | |
long tax = calcTax(income); | |
long progressive = progressive(income); | |
System.out.println("[세율에 의한 세금]:\t\t\t\t" + tax); | |
System.out.println("[누진공제 계산에 의한 세금]:\t\t" + progressive); | |
} | |
static long calcTax(long income){ | |
long sumed_tax = 0L; | |
int taxRate = 0; | |
for(int i = 1 ; i < TaxLine.STAGES.length ; i++){ | |
if(income > TaxLine.STAGES[i]){ | |
double line = TaxLine.STAGES[i-1]; | |
double toAmt = TaxLine.STAGES[i]; | |
taxRate = TaxRate.INTERESTS[i-1]; | |
long calcResult = (long)(toAmt-line) * taxRate / 100; | |
sumed_tax = sumed_tax + calcResult; | |
System.out.printf("%10f * %2d%% = %10d\n", toAmt - line, taxRate, calcResult); | |
if(i == TaxLine.STAGES.length-1){ | |
income -= (long) TaxLine.STAGES[i]; | |
taxRate = TaxRate.INTERESTS[i]; | |
calcResult = income * taxRate / 100; | |
sumed_tax = sumed_tax + calcResult; | |
System.out.printf("%10d * %2d%% = %10d\n", income, taxRate, calcResult); | |
} | |
} | |
else{ | |
income = (long) (income - TaxLine.STAGES[i-1]); | |
taxRate = TaxRate.INTERESTS[i-1]; | |
long calcResult = income * taxRate / 100; | |
sumed_tax = sumed_tax + calcResult; | |
System.out.printf("%10d * %2d%% = %10d\n", income, taxRate, calcResult); | |
break; | |
} | |
} | |
return sumed_tax; | |
} | |
static long progressive(long income){ | |
long progressive_tax = 0L; | |
int progressive_stage = 0; | |
int taxRate = 0; | |
for(int i = 0 ; i < TaxLine.STAGES.length-1 ; i++){ | |
int stage = (int)TaxLine.STAGES[i]; | |
int next_stage = (int)TaxLine.STAGES[i+1]; | |
if(stage < income && income <= next_stage){ | |
progressive_stage = (int)(Progressive.STAGES[i]); | |
taxRate = TaxRate.INTERESTS[i]; | |
break; | |
} | |
if(i == 6){ | |
progressive_stage = (int)(Progressive.STAGES[i+1]); | |
taxRate = TaxRate.INTERESTS[i+1]; | |
} | |
} | |
progressive_tax = income * taxRate / 100 - progressive_stage; | |
return progressive_tax; | |
} | |
} |
Author
dongsub-joung
commented
Jul 8, 2023
`import java.util.ArrayList;
import java.util.Scanner;
class TaxRate{
final static double INTEREST1= 0.06;
final static double INTEREST2= 1.5;
final static double INTEREST3= 2.4;
final static double INTEREST4= 3.5;
final static double INTEREST5= 3.8;
final static double INTEREST6= 0.4;
final static double INTEREST7= 4.2;
final static double INTEREST8= 4.5;
static final double[] INTERESTS= new double[]{INTEREST1, INTEREST2, INTEREST3, INTEREST4, INTEREST5, INTEREST6, INTEREST7, INTEREST8};
}
class TaxLine{
final static double WON= 1000000;
final static double STAGE1= 12 * WON;
final static double STAGE2= 12 * WON;
final static double STAGE3= 46 * WON;
final static double STAGE4= 88 * WON;
final static double STAGE5= 15 * WON;
final static double STAGE6= 30 * WON;
final static double STAGE7= 50 * WON;
final static double STAGE8= 100 * WON;
static final double[] STAGES= new double[]{STAGE1, STAGE2, STAGE3, STAGE4, STAGE5, STAGE6, STAGE7, STAGE8};
}
class Progressive{
final static long WON= 10000;
final static long STAGE1= 0;
final static long STAGE2= 108 * WON;
final static long STAGE3= 522 * WON;
final static long STAGE4= 1490 * WON;
final static long STAGE5= 1940 * WON;
final static long STAGE6= 2540 * WON;
final static long STAGE7= 3540 * WON;
final static long STAGE8= 6540 * WON;
static final long[] STAGES= new long[]{STAGE1, STAGE2, STAGE3, STAGE4, STAGE5, STAGE6, STAGE7, STAGE8};
}
public class Tax {
private long income, amount;
private double rate;
private ArrayList<Long> arrayList;
Tax(long income) {
this.income = income;
this.amount= 0;
}
public void setAmount(long amount) {
this.amount = amount;
}
public void setRate(double rate) {
this.rate = rate;
}
public static void main(String[] args) {
System.out.println("과세금액 계산 프로그램");
System.out.printf("연소득을 입력해 주세요.:\n");
try(Scanner sc = new Scanner(System.in);) {
// long income = sc.nextLong();
long income= 12000000;
// long income= 15000000;
// long income= 20000000;
// long income= 48000000;
// long income= 92000000;
// long income= 192000000;
Tax tax = new Tax(income);
tax= tax.calTax(tax);
tax.printTax(tax);
// System.out.println("[세율에 의한 세금]: " + asPercentageTax(tax));
// System.out.println("[누진공제 계산에 의한 세금]: " + progressiveTax(income));
}catch (Exception e){
System.out.println(e);
}
}
private Tax calTax(Tax tax) {
ArrayList<Long> taxes= new ArrayList<>();
long income= tax.income;
if (TaxLine.STAGE1<= income){
if (TaxLine.STAGE1 == income)
tax.arrayList.add(income);
long remain= (long) (income % TaxLine.STAGE1);
tax.arrayList.add(remain);
}
tax.arrayList= taxes;
return tax;
}
private void printTax(Tax tax) throws Exception {
if (tax.arrayList.size() == 0){
throw new Exception("size 0");
}
long income_part= 0l;
double rate= 0.0;
for (int i=0; i<8; i++){
income_part= tax.arrayList.get(i);
rate= TaxRate.INTERESTS[i];
System.out.printf(String.format("%d * %.2f = %d\n"
, income_part, rate, (long)(income_part*rate)));
}
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment