我的代码中有关在if语句中调用单元的错误

时间:2018-01-24 17:53:27

标签: java netbeans

在我的程序中,它会询问你输入,输入会给你一个相应的推论,但是我的代码一直给我相同的输出,即“Rate Deduction:634.57” 即使它应该给我一个更高的扣除额“扣除费率:1624.57”或“费率扣除:2655.72”

我为生锈的英语道歉,但非常感谢你,如果你愿意帮助我的话。

    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Cp11bTaxActivityKedawenJ jr = new Cp11bTaxActivityKedawenJ();
        headerdisplay();
    }

    public static void headerdisplay() throws IOException
    {
        System.out.println("Monthly Salary Tax Checker");
        Name();
        try
        {
            Salary();
        } catch (IOException e) {
        }

        System.out.println("==============================================================");  
    }

    public static String Name() throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String inputN;
        System.out.print("Input a name: ");
        inputN = br.readLine();
        return inputN;
    }

    public static double Salary() throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
        System.out.print("Input a salary: ");
        double inputS = Double.parseDouble(br.readLine());
        TaxCheck(inputS);
        return 0;
    }

    public static void TaxCheck(Double salary) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
        double totalSalary = salary;
        double salary1 = 15000.00;
        double salary2 = 20000.00;
        double salary3 = 25000.00;
        double salary4 = 30000.00;
        double salary5 = 35000.00;
        double deduction3 = 634.57;
        double deduction4 = 1624.57;
        double deduction5 = 2655.72;

        if (salary >= salary3)
        {
            System.out.println("Rate Deduction: " + deduction3 + "");
            totalSalary = totalSalary - deduction3;
            System.out.println("Total salary: " + totalSalary + "");
        } else {
            System.out.println("This salary does not have a deduction");
            System.out.println("Total salary: "+totalSalary+"");
        }

        again();

        if (salary >= salary4)
        {
            System.out.println("Rate Deduction: " + deduction4 + "");
            totalSalary = totalSalary - deduction4;
            System.out.println("Total salary: " + totalSalary + "");
        } else {
            System.out.println("This salary does not have a deduction");
            System.out.println("Total salary: " + totalSalary + "");
        }

        again();

        if (salary >= salary5)
        {
            System.out.println("Rate Deduction: " + deduction5 + "");
            totalSalary = totalSalary - deduction5;    
            System.out.println("Total salary: " + totalSalary + "");
        } else {
            System.out.println("This salary does not have a deduction");
            System.out.println("Total salary: " + totalSalary + "");
        }

        again();
    }

    public static void again() throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Would you like to try again?:\n [Y] for Yes  [N] for No");
        String choice = br.readLine();
        if (choice.equals("Y"))
        {
            headerdisplay();
        }

        if (choice.equals("N"))
        {
            System.out.println("Thank you for using me! (^_^) Goodbye");
        }
    }
}

2 个答案:

答案 0 :(得分:0)

public static void main(String[] args)throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    //Cp11bTaxActivityKedawenJ jr = new Cp11bTaxActivityKedawenJ ();
    headerdisplay();
}
public static void headerdisplay () throws IOException{

    System.out.println("Monthly Salary Tax Checker");
    Name();
    try{
        Salary();
    }catch(IOException e){
    }
    System.out.println("==============================================================");
}
public static String Name()throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String inputN;
    System.out.print("Input a name: ");
    inputN= br.readLine();
    return inputN;
}
public static double Salary()throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Input a salary: ");
    double inputS = Double.parseDouble(br.readLine());
    TaxCheck (inputS);
    return 0;
}
public static void TaxCheck(Double salary)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    double totalSalary = salary;
    double salary1 = 15000.00;
    double salary2 = 20000.00;
    double salary3 = 25000.00;
    double salary4 = 30000.00;
    double salary5 = 35000.00;
    double deduction3 =  634.57;
    double deduction4 = 1624.57;
    double deduction5 = 2655.72;
  if (salary>=salary5){
        System.out.println("Rate Deduction: "+deduction5+"");
        totalSalary = totalSalary - deduction5;
        System.out.println("Total salary: "+totalSalary+"");
    }
    else if (salary>=salary4){
        System.out.println("Rate Deduction: "+deduction4+"");
        totalSalary = totalSalary - deduction4;
        System.out.println("Total salary: "+totalSalary+"");
    }
    else if (salary>=salary3){
        System.out.println("Rate Deduction: "+deduction3+"");
        totalSalary = totalSalary - deduction3;
        System.out.println("Total salary: "+totalSalary+"");
    }
    else {
        System.out.println("This salary does not have a deduction");
        System.out.println("Total salary: "+totalSalary+"");
    }

    again();
}
public static void again() throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Would you like to try again?:\n [Y] for Yes  [N] for No");
    String choice = br.readLine();
    if (choice.equals("Y")){
        headerdisplay();
    }
    if (choice.equals("N")){
        System.out.println("Thank you for using me! (^_^) Goodbye");
    }
}

答案 1 :(得分:0)

如果您在工资4和工资5中检查过的if,则无法访问代码,因为在if if block check for salary 3之后调用again()

仅在TaxCheck()方法结束时调用nowy_komentarz.post = detale_bajki ... return render(request, 'html page', {'key': 'what you want to return to your context'}) # don't fornget to add some return to your view. 方法。

此外,您应该将工资支票的顺序从高到低更改,即从工资5到工资3。