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());
double MonthTax=salary-5000-insurance-special;
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;
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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("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>