Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

javascript - 基于给定信息的Java税收计算方法?(Java Tax Calculation Method based on given information?)

Create a method called taxAmount that takes two parameters (a String called 'married' and an integer called 'income') and returns an integer containing the tax owed (whole dollar amount, no cents).

(创建一个名为taxAmount的方法,该方法带有两个参数(一个名为“ married”的字符串和一个名为“ income”的整数),并返回一个包含所欠税款的整数(整数,无美分)。)

Use this tax rate schedule to calculate the tax owed:

(使用此税率表来计算所欠税款:)

Status      Taxable income is   Tax owed
Single (S)  <= $32,000          10%
Single (S)  > $32,000           $3,200 + 25% of the amount over $32,000
Married (M) <= $64,000          10%
Married (M) > $64,000           $6,400 + 25% of the amount over $64,000

In your main method, within a loop prompt the user for a status of 'S' (for single), 'M' (for married), or 'X' (to end).

(在您的主要方法中,在循环内提??示用户输入“ S”(单身),“ M”(已婚)或“ X”(结束)状态。)

If they respond 'X', they are done.

(如果他们回答“ X”,他们就完成了。)

If they provide 'S' or 'M', prompt them for an integer amount for income.

(如果他们提供“ S”或“ M”,则提示他们输入整数作为收入。)

Call your taxAmount method, passing in the values supplied by the user and then display a message indicating their tax owed using the returned value.

(调用taxAmount方法,传入用户提供的值,然后显示一条消息,指示使用返回的值欠他们的税款。)

Continue your loop until the user provides an 'X' for the status.

(继续循环,直到用户为状态提供“ X”。)

Verify that the user supplies either an 'S', 'M', or 'X' for the status.

(验证用户是否为状态提供了“ S”,“ M”或“ X”。)

If they enter a different value, notify them that it is invalid and then prompt them for status again.

(如果他们输入其他值,则通知他们无效,然后再次提示他们状态。)

Verify that the user provides an integer value for the salary.

(验证用户是否为工资提供整数值。)

If they enter an invalid value, notify them that it is invalid and then prompt them for salary again.

(如果他们输入了无效的值,请通知他们该值无效,然后再次提示他们发薪。)

Use proper formatting and commenting.

(使用正确的格式和注释。)

This is what I have :

(这就是我所拥有的:)

public class BonusTaxCalculation {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    Scanner scnr = new Scanner(System.in);
    String status;
    int income_1;

    System.out.print("Enter 'S' for signle, 'M' for married or 'X' to end: ");

    status = scnr.next();

    while (scnr.hasNext("[SMX]"))
    {
        while (status!="X")
        {
         System.out.print("Please enter an integer for income: ");
         income_1 = scnr.nextInt();

         while (!scnr.hasNextInt())
         {
          System.out.print("Please enter an integer value!");
          income_1 = scnr.nextInt();
         }
        }
    int TAX = taxAmount(status,income_1);
    }

// TODO code application logic here
    }

    public static int taxAmount(String married, Integer income){
    int taxOwed;
    if (married == "S")
    {
        if (income<=32000)
        {
            taxOwed = (int)(income*0.10);
        }
        else
        {
            taxOwed = (int)(3200+(income-32000)*0.25);
        }
    else if (married == "M")
    {
        if (income <=64000)
        {
            taxOwed = (int)(income*0.10);
        }
        else
        { 
            taxOwed = (int)(6400+(income-64000)*0.25);
        }
    }
    }


    return taxOwed;    
    }
}
  ask by Kristina Mortimer translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...