有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用特定值计算税收

我很难理解如何让我的程序正确计算这些税号
如果单身和应税收入超过 但还没有结束 税是 超过多少

$0
$8,000  10% $0
$8,000  $32,000 $800 + 15%  $8,000
$32,000 
$4,400 + 25%    $32,000
If married and taxable income is over   but not over    the tax is  of the amount over
$0  $16,000 10% $0
$16,000 $64,000 $1,600 + 15%    $16,000
$64,000 
$8,800 + 25%    $64,000
You should prompt the user for their filing status and their taxable income. The user should enter 'S' for single filers and 'M' for married filers.

例如,如果纳税人是单身且收入为10000美元。他们将支付800美元外加2000年(10000-8000)的15%。 这就是我目前掌握的情况

public class Income_tax

{  



 public static final int SINGLE = 1;

   public static final int MARRIED = 2;


   private static final double RATE1 = 0.10;

   private static final double RATE1_SINGLE_LIMIT = 8000;

   private static final double RATE1_MARRIED_LIMIT = 16000;

   private static final double RATE2_SINGLE_LIMIT = 32000;

   private static final double RATE2_MARRIED_LIMIT = 64000;

   private static final double RATE3_SINGLE_LIMIT = 60000;

   private static final double RATE3_MARRIED_LIMIT = 150000;

private static final double RATE2 = 0.15;

private static final double RATE3 = 0.25;




private double income;

   private int status;


   public Income_tax(double anIncome, int aStatus)

   {  

      income = anIncome;

      status = aStatus;

   }



  public double getTax()

   {  

  double tax1 = 0;

  double tax2 = 0;

  if (status == SINGLE)

  {  

     if (income <= RATE1_SINGLE_LIMIT)

     {

        tax1 = RATE1 * income;

     }

     else

     {

        tax1 = RATE1 * RATE1_SINGLE_LIMIT;

        tax2 = RATE2 * (income - RATE1_SINGLE_LIMIT);

     }

  }

   if (income <= RATE3_SINGLE_LIMIT)

  {  
      tax1 = RATE3 * income;


     if (income <= RATE1_MARRIED_LIMIT)

     {
        tax1 = RATE1 * income;

     }
     if (income <= RATE3_MARRIED_LIMIT)
     {
         tax1 = RATE3 * income;
     }

     else 

     {

        tax1 = RATE1 * RATE1_MARRIED_LIMIT;

        tax2 = RATE2 * (income - RATE1_MARRIED_LIMIT);

     }
     if (status == SINGLE)

     {  

        if (income <= RATE2_SINGLE_LIMIT)

        {

           tax1 = RATE2 * income;

        }

        else

        {

           tax1 = RATE1 * RATE2_SINGLE_LIMIT;

           tax2 = RATE1 * (income - RATE2_SINGLE_LIMIT);

        }

     }

     else

     {  

        if (income <= RATE2_MARRIED_LIMIT)

        {
           tax1 = RATE2 * income;

        }

        else 

        {

           tax1 = RATE2 * RATE2_MARRIED_LIMIT;

           tax2 = RATE1 * (income - RATE2_MARRIED_LIMIT);

        }
  }
  return tax1 + tax2; 



 }
    return tax2 + tax1;

}
}

我的计算器课是

    import java.util.Scanner;

public class TaxCalculator {
     @SuppressWarnings("resource")
    public static void main(String[] args)

        {  

           Scanner in = new Scanner(System.in);


           System.out.print("Please enter your anual income [per year]: ");

           double income = in.nextDouble();


           System.out.print("Please enter S for Single and M for Married (S/M) ");

           String input = in.next();

           int status;

           if (input.equals("M")) 

           {

              status = Income_tax.MARRIED;

           }

           else  

           {

              status = Income_tax.SINGLE;

           }

           Income_tax aTaxReturn = new Income_tax(income, status);

           System.out.println(" Your tax is: "

                 + aTaxReturn.getTax());

        }

     }

共 (0) 个答案