首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在我的JavaScript上有一个税务问题

在我的JavaScript上有一个税务问题
EN

Stack Overflow用户
提问于 2018-10-07 07:43:39
回答 1查看 27关注 0票数 -1

我正在尝试在我创建的用于计算税收的JavaScript上获得一些帮助。我感觉我的数学出了点问题,但我认为代码运行正常。当我输入这两个值时,得到的数学结果似乎不准确。如果有人能看一下我的作品,看看我的作品有什么问题,我将不胜感激。

package taxableIncome;
import java.util.Scanner;

public class taxableIncome {
    public static void main(String[] args) {
        System.out.println("Enter filing status: ");
        Scanner input = new Scanner(System.in);
        double x = input.nextDouble();
        if (x == 0) {
            x = 'S';
        } else if (x == 1) {
            x = 'M';
        } else if (x == 2) {
            x = 'J';
        } else if (x == 3) {
            x = 'H';
            }

        System.out.println("Enter taxable income: ");
        input = new Scanner(System.in);
        double y = input.nextInt();
        if (x == 'S') {
        if (y <= 8350) {
            System.out.println(y*.01);
        } else if (y >= 8351 && y<= 33950) {
            System.out.println(y*.15);
        } else if (y >= 33951 && y<= 82250) {
            System.out.println(y*.25);
        } else if (y >= 82251 && y<= 171550) {
            System.out.println(y*.28);
        } else if (y >= 171551 && y<= 372950) {
            System.out.println(y*.33);
        } else System.out.println(y*.35);
        }
        if (x == 'M') {
        if (y <= 8350) {
            System.out.println(y*.01);
        } else if (y >= 8351 && y<= 33950) {
            System.out.println(y*.15);
        } else if (y >= 33951 && y<= 68525) {
            System.out.println(y*.25);
        } else if (y >= 68526 && y<= 104425) {
            System.out.println(y*.28);
        } else if (y >= 104426 && y<= 186475) {
            System.out.println(y*.33);
        } else System.out.println(y*.35);
        }
        if (x == 'J') {
        if (y <= 16700) {
            System.out.println(y*.01);
        } else if (y >= 16701 && y<= 67900) {
            System.out.println(y*.15);
        } else if (y >= 67901 && y<= 137050) {
            System.out.println(y*.25);
        } else if (y >= 137051 && y<= 208850) {
            System.out.println(y*.28);
        } else if (y >= 208851 && y<= 372950) {
            System.out.println(y*.33);
        } else System.out.println(y*.35);
        }
        if (x == 'H') {
        if (y <= 11950) {
            System.out.println(y*.01);
        } else if (y >= 11951 && y<= 45500) {
            System.out.println(y*.15);
        } else if (y >= 45501 && y<= 117450) {
            System.out.println(y*.25);
        } else if (y >= 117451 && y<= 190200) {
            System.out.println(y*.28);
        } else if (y >= 190201 && y<= 372590) {
            System.out.println(y*.33);
        } else System.out.println(y*.35);
}

    }
}
EN

回答 1

Stack Overflow用户

发布于 2018-10-07 08:08:55

我更改了输出,以便向用户提示他可以输入什么。

  • 将其改为存储第一个字符,因为这是您用来确定x和y的第一个字符,因为我记不住所有x和y是什么意思。

  • 从用户输入中读取double,而不是int。

public class taxableIncome {
  public static void main(String[] args) {
    System.out.println("Enter filing status (S,M,J,H): ");
    Scanner input = new Scanner(System.in);
    char status = input.nextLine().toUpperCase().charAt(0);
    System.out.println("Enter taxable income: ");
    input = new Scanner(System.in);
    double taxableIncome = input.nextDouble();
    if (status == 'S') {
      if (taxableIncome <= 8350) {
        System.out.println(taxableIncome * .01);
      } else if (taxableIncome >= 8351 && taxableIncome <= 33950) {
        System.out.println(taxableIncome * .15);
      } else if (taxableIncome >= 33951 && taxableIncome <= 82250) {
        System.out.println(taxableIncome * .25);
      } else if (taxableIncome >= 82251 && taxableIncome <= 171550) {
        System.out.println(taxableIncome * .28);
      } else if (taxableIncome >= 171551 && taxableIncome <= 372950) {
        System.out.println(taxableIncome * .33);
      } else
        System.out.println(taxableIncome * .35);
    }
    if (status == 'M') {
      if (taxableIncome <= 8350) {
        System.out.println(taxableIncome * .01);
      } else if (taxableIncome >= 8351 && taxableIncome <= 33950) {
        System.out.println(taxableIncome * .15);
      } else if (taxableIncome >= 33951 && taxableIncome <= 68525) {
        System.out.println(taxableIncome * .25);
      } else if (taxableIncome >= 68526 && taxableIncome <= 104425) {
        System.out.println(taxableIncome * .28);
      } else if (taxableIncome >= 104426 && taxableIncome <= 186475) {
        System.out.println(taxableIncome * .33);
      } else
        System.out.println(taxableIncome * .35);
    }
    if (status == 'J') {
      if (taxableIncome <= 16700) {
        System.out.println(taxableIncome * .01);
      } else if (taxableIncome >= 16701 && taxableIncome <= 67900) {
        System.out.println(taxableIncome * .15);
      } else if (taxableIncome >= 67901 && taxableIncome <= 137050) {
        System.out.println(taxableIncome * .25);
      } else if (taxableIncome >= 137051 && taxableIncome <= 208850) {
        System.out.println(taxableIncome * .28);
      } else if (taxableIncome >= 208851 && taxableIncome <= 372950) {
        System.out.println(taxableIncome * .33);
      } else
        System.out.println(taxableIncome * .35);
    }
    if (status == 'H') {
      if (taxableIncome <= 11950) {
        System.out.println(taxableIncome * .01);
      } else if (taxableIncome >= 11951 && taxableIncome <= 45500) {
        System.out.println(taxableIncome * .15);
      } else if (taxableIncome >= 45501 && taxableIncome <= 117450) {
        System.out.println(taxableIncome * .25);
      } else if (taxableIncome >= 117451 && taxableIncome <= 190200) {
        System.out.println(taxableIncome * .28);
      } else if (taxableIncome >= 190201 && taxableIncome <= 372590) {
        System.out.println(taxableIncome * .33);
      } else
        System.out.println(taxableIncome * .35);
    }
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52684260

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档