這個(gè)題目很有意思。不用這么復(fù)雜。大概10幾句就做完了。
創(chuàng)新互聯(lián)建站長(zhǎng)期為千余家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為紅寺堡企業(yè)提供專業(yè)的做網(wǎng)站、成都網(wǎng)站設(shè)計(jì),紅寺堡網(wǎng)站改版等技術(shù)服務(wù)。擁有10年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
以前我用C#做過的。先把邏輯簡(jiǎn)化了。幾個(gè)IF THEN就搞定
public?static?void?main(String[]?args)?{
System.out.println("輸入你的收入:");
Scanner?input?=?new?Scanner(System.in);
double?money?=?input.nextFloat();
double?tax?=?0;
if(money?=?500){
tax?=?money?*?0.05;
}else?if(money??500??money?=?20000){
tax?=?money?*?0.1;
}
//?.....
System.out.println("納稅:"?+?tax?+?"?元");
}
java計(jì)算個(gè)稅例子:
/**
* @author Kun Sun
* @Date: 2013.10.15
*/
public class Employee { // 雇員類
private String ID; ? ? ? // ID
private String name; ? ? // 姓名
private int salary; ? ? ?// 工資薪金所得
private int insureHome; ?// “五險(xiǎn)一金”數(shù)額
private int deduct; ? ? ?// 扣除數(shù)額
Employee(){
}
Employee(String ID,String name){ // 帶參數(shù)的構(gòu)造方法
this.ID = ID;
this.name = name;
}
Employee(String ID,String name,int salary,int insureHome,int deduct){ ?// 帶參數(shù)的構(gòu)造方法
this.ID = ID;
this.name = name;
this.salary = salary;
this.insureHome = insureHome;
? ?this.deduct = deduct;
}
public String getID() {
return ID;
}
public String getName() {
return name;
}
public int getSalary() {
return salary;
}
public int getInsureHome() {
return insureHome;
}
public int getDeduct() {
return deduct;
}
public void setID(String iD) {
ID = iD;
}
public void setName(String name) {
this.name = name;
}
public void setSalary(int salary) {
this.salary = salary;
}
public void setInsureHome(int insureHome) {
this.insureHome = insureHome;
}
public void setDeduct(int deduct) {
this.deduct = deduct;
}
public void selfValue(){ // 個(gè)人所得稅具體計(jì)算
double sefValue;
? ?if(salary=0 salary1500){
? ? sefValue = (double)(salary-insureHome-deduct)*0.03 - 0;
? ?}else if(salary=1500 salary4500){
? ? sefValue = (double)(salary-insureHome-deduct)*0.1 - 105;
? ?}else if(salary=4500 salary9000){
? ? sefValue = (double)(salary-insureHome-deduct)*0.2 - 555;
? ?}else if(salary=9000 salary35000){
? ? sefValue = (double)(salary-insureHome-deduct)*0.25 - 1005;
? ?}else if(salary=35000 salary55000){
? ? sefValue = (double)(salary-insureHome-deduct)*0.30 - 2755;
? ?}else if(salary=55000 salary80000){
? ? sefValue = (double)(salary-insureHome-deduct)*0.35 - 5505;
? ?}else{
? ? sefValue = (double)(salary-insureHome-deduct)*0.45 - 13505;
? ?}
? ?System.out.println(sefValue);
}
}
// 用于測(cè)試雇員類
public class MainClass {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("第一種調(diào)用方法:");
Employee emp = new Employee("1001","Sun");
emp.setSalary(12345);
emp.setInsureHome(890);
emp.setDeduct(55);
System.out.println("編號(hào)為"+emp.getID()+",姓名是"+emp.getName()+" 的應(yīng)納稅額是:");
? ?emp.selfValue();
?
? ?System.out.println("------------------------\n第二種調(diào)用方法:");
? ?Employee emp2 = new Employee("1001","Sun",12345,890,55);
System.out.println("編號(hào)為"+emp2.getID()+",姓名是"+emp2.getName()+" 的應(yīng)納稅額是:");
? ?emp2.selfValue();
?
? ?System.out.println("------------------------\n第二種調(diào)用方法:");
? ?Employee emp3 = new Employee();
? ?emp3.setID("1001");
? ?emp3.setName("Sun");
emp3.setSalary(12345);
emp3.setInsureHome(890);
emp3.setDeduct(55);
System.out.println("編號(hào)為"+emp3.getID()+",姓名是"+emp3.getName()+" 的應(yīng)納稅額是:");
? ?emp3.selfValue();
}
}
運(yùn)行結(jié)果:
public float ComputeTax(float income) //income為工資
{
float f_income=income-800; //起征基數(shù)為800,同時(shí)也可以參數(shù)化處理
float[] tax_line={0f,500f,2000f,5000f,20000f,40000f,60000f,80000f,100000f};//計(jì)算個(gè)人所得稅的檔次(假設(shè)員工為中國(guó)國(guó)籍,因?yàn)閲?guó)籍不同起征點(diǎn)數(shù)不同,稅率不同。)
float[] tax_rate={0f,0.05f,0.10f,0.15f,0.20f,0.25f,0.30f,0.35f,0.40f}; //各檔次稅率
float[] tax_sub={0.f,25f,125f,375f,1375f,3375f,6375f,10375f,15375f}; //采用了簡(jiǎn)化算法
int i_tax_level=0; //為了計(jì)算簡(jiǎn)便,把工資進(jìn)行分檔
while(f_incometax_line[i_tax_level]i_tax_leveltax_line.length)
{
i_tax_level++;
};
if(i_tax_level0)
{
float f_tax=tax_sub[i_tax_level-1]+(f_income-tax_line[i_tax_level-1])*tax_rate[i_tax_level]; //算稅的公式
return f_tax;
}
else
{
return 0f;
}
}