import javax.swing.JOptionPane;//引用javax.swing包里的JOptionPane类 /** * 美国的个人所得税时给予纳税人的情况和应征收的收入计算的。 * 纳税人情况共有四种: 单身纳税人、已婚共同纳税人、已婚单缴纳税人和家庭纳税人。 * ------------------------------------------------------------------------------- * 税率 单身纳税人 已婚共同纳税人 已婚单缴纳税人 家庭纳税人 * 10% 低于等于6000 低于等于12000 低于等于6000 低于等于10000 * 15% 6001-27950 12001-46700 6001-23350 10001-37450 * 27% 27951-67700 46701-112850 23351-56425 37451-96700 * 30% 67701-141250 112851-171950 56426-85975 96701-156600 * 35% 141251-307050 171951-307050 85976-153525 156601-307050 * 38.6% 307051及以上 307051及以上 153526及以上 307051及以上 * ------------------------------------------------------------------------------- * * @author * */ public class nan {//新建public的nan类 /** * @param args */ public static void main(String[] args) {//主方法 String statusString = JOptionPane.showInputDialog(null, "输入纳税人身份/n" + "(0-单身纳税人, 1-已婚共同纳税人,/n" + "2-已婚单缴纳税人, 3-家庭纳税人)", "计算税金 输入:", JOptionPane.QUESTION_MESSAGE);//输入提示框,要求输入0,1,2,3,4,数字代表不同的纳税人 int status = Integer.parseInt(statusString);//将输入烦人字符串强制转换成integer类型 // Prompt the user to enter taxable income String incomeString = JOptionPane.showInputDialog(null, "输入须纳税的收入:",//输入提示框, "计算税金 输入:", JOptionPane.QUESTION_MESSAGE);//我发现并没有这个计算税金的提示框 double income = Double.parseDouble(incomeString);//将收入类型从String类型强制转换为double类型 // Compute tax double tax = 0;//定义一个double类型税金变量tax为0 //+++++++++++++++++++++++++++++++++++++++// if (status == 0) { // Compute tax for single filers//首要前提如果纳税人为单身纳税人 if (income <= 6000)//single的收入小于或等于6000 tax = income * 0.10;//税金等于收入的10% else if (income <= 27950)//single的收入小于等于27950 tax = 6000 * 0.10 + (income - 6000) * 0.15;//税金等于收入高于6000部分的15%加上6000的税金 else if (income <= 67700)//single的收入小于等于67700 tax = 6000 * 0.10 + (27950 - 6000) * 0.15 + (income - 27950) * 0.27; else if (income <= 141250)//single的收入小于141250 tax = 6000 * 0.10 + (27950 - 6000) * 0.15 + (67700 - 27950) * 0.27 + (income - 67700) * 0.30; else if (income <= 307050)//single的收入小雨307050 tax = 6000 * 0.10 + (27950 - 6000) * 0.15 + (67700 - 27950) * 0.27 + (141250 - 67700) * 0.30 + (income - 141250) * 0.35; else//其他情况 tax = 6000 * 0.10 + (27950 - 6000) * 0.15 + (67700 - 27950) * 0.27 + (141250 - 67700) * 0.30 + (307050 - 141250) * 0.35 + (income - 307050) * 0.386; } //+++++++++++++++++++++++++++++++// else if (status == 1) { // Compute tax for married file jointly // Left as exercise//纳税人为已婚共同纳税人 if (income <= 12000) tax = income * 0.10; else if (income <= 46700) tax = 6000 * 0.10 + (income - 12000) * 0.15; else if (income <= 112850) tax = 6000 * 0.10 + (46700 - 12000) * 0.15 + (income - 46700) * 0.27; else if (income <= 171950) tax = 6000 * 0.10 + (46700 - 12000) * 0.15 + (112850 - 46700) * 0.27 + (income - 112850) * 0.30; else if (income <= 307050) tax = 6000 * 0.10 + (46700 - 12000) * 0.15 + (67700 - 46700) * 0.27 + (171950 - 112850) * 0.30 + (income - 171950) * 0.35; else tax = 6000 * 0.10 + (27950 - 12000) * 0.15 + (67700 - 46700) * 0.27 + (141250 - 112850) * 0.30 + (307050 - 171950) * 0.35 + (income - 307050) * 0.386; } //+++++++++++++++++++++++++++++++// else if (status == 2) { // Compute tax for married separately // Left as exercise//如果纳税人为已婚单缴纳税人 if (income <= 6000) tax = income * 0.10; else if (income <= 23350) tax = 6000 * 0.10 + (income - 6000) * 0.15; else if (income <= 56425) tax = 6000 * 0.10 + (23350 - 6000) * 0.15 + (income - 23350) * 0.27; else if (income <= 85975) tax = 6000 * 0.10 + (23350 - 6000) * 0.15 + (56425 - 23350) * 0.27 + (income - 56425) * 0.30; else if (income <= 153525) tax = 6000 * 0.10 + (23350 - 6000) * 0.15 + (56425 - 23350) * 0.27 + (85975 - 56425) * 0.30 + (income - 85975) * 0.35; else tax = 6000 * 0.10 + (23350 - 6000) * 0.15 + (56425 - 23350) * 0.27 + (85975 - 56425) * 0.30 + (153525 - 85975) * 0.35 + (income - 153525) * 0.386; } //+++++++++++++++++++++++++++++++// else if (status == 3) { // Compute tax for head of household // Left as exercise//如果是家庭纳税人 if (income <= 10000) tax = income * 0.10; else if (income <= 37450) tax = 6000 * 0.10 + (income - 10000) * 0.15; else if (income <= 96700) tax = 6000 * 0.10 + (37450 - 10000) * 0.15 + (income - 37450) * 0.27; else if (income <= 156600) tax = 6000 * 0.10 + (37450 - 10000) * 0.15 + (96700 - 37450) * 0.27 + (income - 96700) * 0.30; else if (income <= 307050) tax = 6000 * 0.10 + (37450 - 10000) * 0.15 + (67700 - 37450) * 0.27 + (156600 - 96700) * 0.30 + (income - 156600) * 0.35; else tax = 6000 * 0.10 + (27950 - 10000) * 0.15 + (67700 - 37450) * 0.27 + (141250 - 96700) * 0.30 + (307050 - 156600) * 0.35 + (income - 307050) * 0.386; } //+++++++++++++++++++++++++++++++++++++++// else {//上面的if全部不符合的话 System.out.println("错误: 不合法的身份!");//则输出"错误:不合法的身份!" System.exit(0);//程序运行的这里弹出 } // Display the result JOptionPane.showMessageDialog(null, "税金是:" + (int) (tax * 100) / 100.0, "计算税金 输出:", JOptionPane.INFORMATION_MESSAGE);//输出税金,将整型转换为Double,这句需要解释一下 } }