如何使用数组计算数字范围?

时间:2017-02-23 06:12:10

标签: java

我的任务很简单。有人为他们的收入输入一个数字,如果它低于9000,其税率为10%,超过15%,等等。

但其中一项要求说明"您将在每种方法中将收入范围组织为一个数组,并选择一个数组记录来计算税收范围内的特定税收"

那怎么办?没有数组只取特定值而不取值范围

到目前为止这是我的代码

public static int calcTax(int status, int income)
{
      if (status == 0)
      {
         return singleFiling(income);
      }
      if (status == 1)
      {   
         return jointFiling(income);
      }
      if (status == 2)
      {   
         return headFiling(income);
      }
      else
          System.out.println("Error: invalid status. Enter a number between 0 to 2 only.");
    return income;

      }

static int ninek = 9075;
static int thrirtysixk = 36900;
static int eightyninek = 89350;
static int oneeightysixk = 186350;
static int fourofivek = 405100;
static int fourosixk = 406750;
static int eighteenk = 18150;
static int seventythreek = 73800;
static int onefortyeightk = 148850;
static int twotwentysixk = 226850;
static int fourfivesevenk = 457600;
static int twelveninefifty = 12950;
static int fourninek = 49400;
static int onetwentysevenk = 127550;
static int twoosixk = 206600;
static int fpurthreetwok = 432200;

 static double tax = 0;
 static int singleFiling(double userIncome)
{
    if (userIncome >= 1 && userIncome <= ninek )
        tax = userIncome * 0.10;    

System.out.println("Your payable Federal tax is: " + tax);

return 0;
}
 static int jointFiling(double userIncome)
    {
        if (userIncome >= 1 && userIncome <= oneeightysixk )
            tax = userIncome * 0.10;    

    System.out.println("Your payable Federal tax is: " + tax);

    return 0;
    }
  static int headFiling(double userIncome)
  {
      if (userIncome >= 1 && userIncome <= twelveninefifty )
            tax = userIncome * 0.10;    

    System.out.println("Your payable Federal tax is: " + tax);

    return 0;
  }
}

0 个答案:

没有答案