Java IRS税务计算/若有其他陈述/已婚或单身

时间:2015-09-22 02:12:36

标签: java string if-statement math java.util.scanner

我的任务是创建一个小型IRS临时税计算器。 要完成的任务目标是:

写一个课程 提示用户输入以下信息:

申请状态:单身或已婚(单身为1,结婚为2)

应税收入

计算并打印:

归档状态

应税收入

联邦税

我应该对每个参数进行特定的计算,包括代码中包含的0到27050,27050到65500等等。 我遇到的真正问题是我似乎无法将数字显示出来。

我的代码如下:

import java.util.Scanner;
    public class P4_Icel_Murad_IRS
    {
        public static void main(String[] args){
            Scanner in = new Scanner(System.in);
            System.out.printf("Enter Marital Status: (Single = 1, Married = 2):");
            int relation = in.nextInt();
            System.out.printf("Enter taxable income:");
            int tax = in.nextInt();
            if (relation == 1){
                String status = "Single";
                if (tax <= 27050){
                    double tax2 = tax - 0.0;
                    double tax3 = (tax2 * 0.15);
                    System.out.printf(status,tax,tax3);
                }else if (27050 < tax && tax >= 65550){
                    double tax2 = (tax - 27050.0)* 0.275;
                    double tax3 = 4057.5 + tax2;
                }else if (65550 < tax && tax <= 136750){
                    double tax2 = (tax - 65550.0) * 0.305;
                    double tax3 = 14645.0 + tax2;
                }else if (136750 < tax && tax <= 297350){
                    double tax2 = (tax - 136750.0 - tax) * 0.355;
                    double tax3 = 36361.00 + tax2;
                }else if (297350 < tax && tax <= 1e100){
                    double tax2 = (tax - 297350) * 0.391;
                    double tax3 = 93374.0 + tax2;
                }
            }
                if (relation == 2){
                String status = "Married";
                if (tax <= 27050){
                    double tax2 = tax - 0.0;
                    double tax3 = (tax2 * 0.15);
                    System.out.printf(status,tax,tax3);
                }else if (27050 < tax && tax >= 65550){
                    double tax2 = (tax - 27050.0)* 0.275;
                    double tax3 = 4057.5 + tax2;
                }else if (65550 < tax && tax <= 136750){
                    double tax2 = (tax - 65550.0) * 0.305;
                    double tax3 = 14645.0 + tax2;
                }else if (136750 < tax && tax <= 297350){
                    double tax2 = (tax - 136750.0 - tax) * 0.355;
                    double tax3 = 36361.00 + tax2;
                }else if (297350 < tax && tax <= 1e100){
                    double tax2 = (tax - 297350) * 0.391;
                    double tax3 = 93374.0 + tax2;
                }
            }    

        }
    }

1 个答案:

答案 0 :(得分:0)

您正在声明变量     TAX2     tax3 如果是块,则在个人本地。

您可以在其中一个块中打印,但不能全部打印。

将声明移到

int tax = in.nextInt();
double tax2 = 0;
double tax3 = 0;

然后在所有逻辑的末尾打印出它们的值。