个税计算器

package com.atomic.moretool;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

public class PersonTaxCal extends AppCompatActivity {
    private EditText Insurance,Salary,Special;
    private TextView ShowTax;
    private int btncount=2;
    @SuppressLint("WrongThread")
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_person_tax_cal);
        Button cal = findViewById(R.id.cal);
        Salary=findViewById(R.id.salary);
        Insurance=findViewById(R.id.insurance);
        Special=findViewById(R.id.special);
        Salary.setSelectAllOnFocus(true);
        Insurance.setSelectAllOnFocus(true);
        Special.setSelectAllOnFocus(true);
        ShowTax=findViewById(R.id.show_tax);
        cal.setOnClickListener(view -> {
            btncount++;
            if (!String.valueOf(btncount).matches("([1-9]\\d*)?[02468]")){
                init();
            }else{
                Intent intent=new Intent(getApplicationContext(),MainActivity.class);
                startActivity(intent);
                Toast.makeText(getApplicationContext(), "自动返回--可点击重新计算", Toast.LENGTH_SHORT).show();
            }
        });
    }
    @SuppressLint("SetTextI18n")
    private void init() {
        double salary=Double.parseDouble(Salary.getText().toString().trim());//工资
        double insurance=Double.parseDouble(Insurance.getText().toString().trim());//五险一金
        double special=Double.parseDouble(Special.getText().toString().trim());//专项附加扣除
        //应纳税额=应纳税所得额x适用税率-速算扣除数
        //应纳税所得额=收入总额-个人所得税起征点-五险一金-专项附加扣除-其它
        //个人所得税起征点5000
        //1月 (25000-5000-2500-2000)*1*0.03 465
        //2月 (25000-5000-2500-2000)*2*0.03-465 465
        //3月 (25000-5000-2500-2000)*3*0.1-2520-465-465 1200
        //全年 (25000-5000-2500-2000)*12*0.2-16920 20280
        double MonthTax=salary-5000-insurance-special; //15500
        double YearTax=MonthTax*12;//年应纳税所得额
        double tax = 0;//年税额
        if (YearTax<=0){
            tax=0;
        }else if (YearTax>0 && YearTax<=36000){
            tax=YearTax*0.03-0;
        }else if (YearTax>36000 && YearTax<=144000){
            tax=YearTax*0.1-2520;
        }else if (YearTax>144000 && YearTax<=300000){
            tax=YearTax*0.2-16920;
        }else if (YearTax>300000 && YearTax<=420000){
            tax=YearTax*0.25-31920;
        }else if (YearTax>420000 && YearTax<=660000){
            tax=YearTax*0.3-52920;
        }else if (YearTax>660000 && YearTax<=960000){
            tax=YearTax*0.35-85920;
        }else if (YearTax>960000){
            tax=YearTax*0.45-181920;
        }
        double one=MonthTax*1;
        double two=MonthTax*2;
        double three=MonthTax*3;
        double four=MonthTax*4;
        double five=MonthTax*5;
        double six=MonthTax*6;
        double seven=MonthTax*7;
        double eight=MonthTax*8;
        double nine=MonthTax*9;
        double ten=MonthTax*10;
        double eleven=MonthTax*11;
        double twelve=MonthTax*12;
        //1月
        if (one<=0){
            one=0;
        }else if (one>0 && one<=36000){
            one=one*0.03;
        }else if (one>36000 && one<=144000){
            one=one*0.1-2520;
        }else if (one>144000 && one<=300000){
            one=one*0.2-16920;
        }else if(one>300000 && one<=420000){
            one=one*0.25-31920;
        }else if (one>420000 && one<=660000){
            one=one*0.3-52920;
        }else if (one>660000 && one<=960000){
            one=one*0.35-85920;
        }else if (one>960000){
            one=one*0.45-181920;
        }
        //2月
        if (two<=0){
            two=0;
        }else if (two>0 && two<=36000){
            two=two*0.03-one;
        }else if (two>36000 && two<=144000){
            two=two*0.1-2520-one;
        }else if (two>144000 && two<=300000){
            two=two*0.2-16920-one;
        }else if(two>300000 && two<=420000){
            two=two*0.25-31920-one;
        }else if (two>420000 && two<=660000){
            two=two*0.3-52920-one;
        }else if (two>660000 && two<=960000){
            two=two*0.35-85920-one;
        }else if (two>960000){
            two=two*0.45-181920-one;
        }
        //3月
        if (three<=0){
            three=0;
        }else if (three>0 && three<=36000){
            three=three*0.03-two-one;
        }else if (three>36000 && three<=144000){
            three=three*0.1-2520-two-one;
        }else if (three>144000 && three<=300000){
            three=three*0.2-16920-two-one;
        }else if(three>300000 && three<=420000){
            three=three*0.25-31920-two-one;
        }else if (three>420000 && three<=660000){
            three=three*0.3-52920-two-one;
        }else if (three>660000 && three<=960000){
            three=three*0.35-85920-two-one;
        }else if (three>960000){
            three=three*0.45-181920-two-one;
        }
        //4月
        if (four<=0){
            four=0;
        }else if (four>0 && four<=36000){
            four=four*0.03-three-two-one;
        }else if (four>36000 && four<=144000){
            four=four*0.1-2520-three-two-one;
        }else if (four>144000 && four<=300000){
            four=four*0.2-16920-three-two-one;
        }else if(four>300000 && four<=420000){
            four=four*0.25-31920-three-two-one;
        }else if (four>420000 && four<=660000){
            four=four*0.3-52920-three-two-one;
        }else if (four>660000 && four<=960000){
            four=four*0.35-85920-three-two-one;
        }else if (four>960000){
            four=four*0.45-181920-three-two-one;
        }
        //5月
        if (five<=0){
            five=0;
        }else if (five>0 && five<=36000){
            five=five*0.03-four-three-two-one;
        }else if (five>36000 && five<=144000){
            five=five*0.1-2520-four-three-two-one;
        }else if (five>144000 && five<=300000){
            five=five*0.2-16920-four-three-two-one;
        }else if(five>300000 && five<=420000){
            five=five*0.25-31920-four-three-two-one;
        }else if (five>420000 && five<=660000){
            five=five*0.3-52920-four-three-two-one;
        }else if (five>660000 && five<=960000){
            five=five*0.35-85920-four-three-two-one;
        }else if (five>960000){
            five=five*0.45-181920-four-three-two-one;
        }
        //6月
        if (six<=0){
            six=0;
        }else if (six>0 && six<=36000){
            six=six*0.03-five-four-three-two-one;
        }else if (six>36000 && six<=144000){
            six=six*0.1-2520-five-four-three-two-one;
        }else if (six>144000 && six<=300000){
            six=six*0.2-16920-five-four-three-two-one;
        }else if(six>300000 && six<=420000){
            six=six*0.25-31920-five-four-three-two-one;
        }else if (six>420000 && six<=660000){
            six=six*0.3-52920-five-four-three-two-one;
        }else if (six>660000 && six<=960000){
            six=six*0.35-85920-five-four-three-two-one;
        }else if (six>960000){
            six=six*0.45-181920-five-four-three-two-one;
        }
        //7月
        if (seven<=0){
            seven=0;
        }else if (seven>0 && seven<=36000){
            seven=seven*0.03-six-five-four-three-two-one;
        }else if (seven>36000 && seven<=144000){
            seven=seven*0.1-2520-six-five-four-three-two-one;
        }else if (seven>144000 && seven<=300000){
            seven=seven*0.2-16920-six-five-four-three-two-one;
        }else if(seven>300000 && seven<=420000){
            seven=seven*0.25-31920-six-five-four-three-two-one;
        }else if (seven>420000 && seven<=660000){
            seven=seven*0.3-52920-six-five-four-three-two-one;
        }else if (seven>660000 && seven<=960000){
            seven=seven*0.35-85920-six-five-four-three-two-one;
        }else if (seven>960000){
            seven=seven*0.45-181920-six-five-four-three-two-one;
        }
        //8月
        if (eight<=0){
            eight=0;
        }else if (eight>0 && eight<=36000){
            eight=eight*0.03-seven-six-five-four-three-two-one;
        }else if (eight>36000 && eight<=144000){
            eight=eight*0.1-2520-seven-six-five-four-three-two-one;
        }else if (eight>144000 && eight<=300000){
            eight=eight*0.2-16920-seven-six-five-four-three-two-one;
        }else if(eight>300000 && eight<=420000){
            eight=eight*0.25-31920-seven-six-five-four-three-two-one;
        }else if (eight>420000 && eight<=660000){
            eight=eight*0.3-52920-seven-six-five-four-three-two-one;
        }else if (eight>660000 && eight<=960000){
            eight=eight*0.35-85920-seven-six-five-four-three-two-one;
        }else if (eight>960000){
            eight=eight*0.45-181920-seven-six-five-four-three-two-one;
        }
        //9月
        if (nine<=0){
            nine=0;
        }else if (nine>0 && nine<=36000){
            nine=nine*0.03-eight-seven-six-five-four-three-two-one;
        }else if (nine>36000 && nine<=144000){
            nine=nine*0.1-2520-eight-seven-six-five-four-three-two-one;
        }else if (nine>144000 && nine<=300000){
            nine=nine*0.2-16920-eight-seven-six-five-four-three-two-one;
        }else if(nine>300000 && nine<=420000){
            nine=nine*0.25-31920-eight-seven-six-five-four-three-two-one;
        }else if (nine>420000 && nine<=660000){
            nine=nine*0.3-52920-eight-seven-six-five-four-three-two-one;
        }else if (nine>660000 && nine<=960000){
            nine=nine*0.35-85920-eight-seven-six-five-four-three-two-one;
        }else if (nine>960000){
            nine=nine*0.45-181920-eight-seven-six-five-four-three-two-one;
        }
        //10月
        if (ten<=0){
            ten=0;
        }else if (ten>0 && ten<=36000){
            ten=ten*0.03-nine-eight-seven-six-five-four-three-two-one;
        }else if (ten>36000 && ten<=144000){
            ten=ten*0.1-2520-nine-eight-seven-six-five-four-three-two-one;
        }else if (ten>144000 && ten<=300000){
            ten=ten*0.2-16920-nine-eight-seven-six-five-four-three-two-one;
        }else if(ten>300000 && ten<=420000){
            ten=ten*0.25-31920-nine-eight-seven-six-five-four-three-two-one;
        }else if (ten>420000 && ten<=660000){
            ten=ten*0.3-52920-nine-eight-seven-six-five-four-three-two-one;
        }else if (ten>660000 && ten<=960000){
            ten=ten*0.35-85920-nine-eight-seven-six-five-four-three-two-one;
        }else if (ten>960000){
            ten=ten*0.45-181920-nine-eight-seven-six-five-four-three-two-one;
        }
        //11月
        if (eleven<=0){
            eleven=0;
        }else if (eleven>0 && eleven<=36000){
            eleven=eleven*0.03-ten-nine-eight-seven-six-five-four-three-two-one;
        }else if (eleven>36000 && eleven<=144000){
            eleven=eleven*0.1-2520-ten-nine-eight-seven-six-five-four-three-two-one;
        }else if (eleven>144000 && eleven<=300000){
            eleven=eleven*0.2-16920-ten-nine-eight-seven-six-five-four-three-two-one;
        }else if(eleven>300000 && eleven<=420000){
            eleven=eleven*0.25-31920-ten-nine-eight-seven-six-five-four-three-two-one;
        }else if (eleven>420000 && eleven<=660000){
            eleven=eleven*0.3-52920-ten-nine-eight-seven-six-five-four-three-two-one;
        }else if (eleven>660000 && eleven<=960000){
            eleven=eleven*0.35-85920-ten-nine-eight-seven-six-five-four-three-two-one;
        }else if (eleven>960000){
            eleven=eleven*0.45-181920-ten-nine-eight-seven-six-five-four-three-two-one;
        }
        //12月
        if (twelve<=0){
            twelve=0;
        }else if (twelve>0 && twelve<=36000){
            twelve=twelve*0.03-eleven-ten-nine-eight-seven-six-five-four-three-two-one;
        }else if (twelve>36000 && twelve<=144000){
            twelve=twelve*0.1-2520-eleven-ten-nine-eight-seven-six-five-four-three-two-one;
        }else if (twelve>144000 && twelve<=300000){
            twelve=twelve*0.2-16920-eleven-ten-nine-eight-seven-six-five-four-three-two-one;
        }else if(twelve>300000 && twelve<=420000){
            twelve=twelve*0.25-31920-eleven-ten-nine-eight-seven-six-five-four-three-two-one;
        }else if (twelve>420000 && twelve<=660000){
            twelve=twelve*0.3-52920-eleven-ten-nine-eight-seven-six-five-four-three-two-one;
        }else if (twelve>660000 && twelve<=960000){
            twelve=twelve*0.35-85920-eleven-ten-nine-eight-seven-six-five-four-three-two-one;
        }else if (twelve>960000){
            twelve=twelve*0.45-181920-eleven-ten-nine-eight-seven-six-five-four-three-two-one;
        }
        /*Log.i("tag1",String.valueOf(one));
        Log.i("tag2",String.valueOf(two));
        Log.i("tag3",String.valueOf(three));
        Log.i("tag4",String.valueOf(four));
        Log.i("tag5",String.valueOf(five));
        Log.i("tag6",String.valueOf(six));
        Log.i("tag7",String.valueOf(seven));
        Log.i("tag8",String.valueOf(eight));
        Log.i("tag9",String.valueOf(nine));
        Log.i("tag10",String.valueOf(ten));
        Log.i("tag11",String.valueOf(eleven));
        Log.i("tag12",String.valueOf(twelve));*/
        Log.i("tagall",String.valueOf(one+two+three+four+five+six+seven+eight+nine+ten+eleven+twelve));
        List<Double> list=new ArrayList<>();
        list.add(one);
        list.add(two);
        list.add(three);
        list.add(four);
        list.add(five);
        list.add(six);
        list.add(seven);
        list.add(eight);
        list.add(nine);
        list.add(ten);
        list.add(eleven);
        list.add(twelve);
        for (int i=0;i<12;i++){
            TextView textView=new TextView(this);
            LinearLayout layout=findViewById(R.id.line2);
            int x=i+1;
            textView.setText(x+"月税额:"+list.get(i));
            textView.setTextSize(14);
            layout.addView(textView);
        }
        ShowTax.setText("全年累计预扣预缴税额:"+ tax);
    }
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_margin="15sp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".PersonTaxCal">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:textSize="14sp"
            android:text="工资收入:"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <EditText
            android:inputType="number"
            android:text="25000"
            android:id="@+id/salary"
            android:textSize="14sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:textSize="14sp"
            android:text="五险一金:"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <EditText
            android:inputType="number"
            android:text="2500"
            android:id="@+id/insurance"
            android:textSize="14sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:textSize="14sp"
            android:text="专项附加扣除:"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <EditText
            android:inputType="number"
            android:text="2000"
            android:id="@+id/special"
            android:textSize="14sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>
    <Button
        android:layout_marginBottom="10sp"
        android:layout_marginTop="10sp"
        android:background="@drawable/button_style"
        android:id="@+id/cal"
        android:textSize="12sp"
        android:text="计算"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView
        android:layout_marginBottom="5sp"
        android:id="@+id/show_tax"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:id="@+id/line2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" />
    </ScrollView>

</LinearLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Atomic_space

你的鼓励就是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值