*6.15(金融应用:打印税表)程序清单3-5给出了计算税款的程序。使用下面的方法体编写一个计算税款的方法。使用这个方法编写程序

  • 题目
    • 题目描述
    • 破题
    • 程序清单3-5(非本题):代码不全
  • 补充代码:编程练习题3.13 / 程序清单3-5完善版
  • 本题代码

题目

题目描述

*6.15(金融应用:打印税表)程序清单3-5给出了计算税款的程序。
使用下面的方法体编写一个计算税款的方法:
public static double computeTax(int status, double taxableIncome)
使用这个方法编写程序,打印可征税收入从50 000美元到60 000美元,收入间隔为50美元的所有以下婚姻状态的纳税表,如图所示:

原书提示:使用Math.round将税收舍入为整数,即:Math.round(computeTax(status, taxableIncome))

破题

status参数对应婚姻状态,在computeTax()这个计算税款的方法中,需要status参数的数值来确定不同层次税率
computeTax()仅完成税款计算其它功能,其它功能均由主方法承担

程序清单3-5(非本题):代码不全

import java.util.Scanner;public class qingdan {public static void main(String[] args) {// Create a ScannerScanner input = new Scanner(System.in);// Prompt the user to enter filing statusSystem.out.println("(0-single filer, 1-married jointly or " +"qualifying widow(er), 2-married separately, 3-head of " +"household) Enter the filing status:");int status = input.nextInt();// Prompt the user to enter taxable incomeSystem.out.println("Enter the taxable income:");double income = input.nextDouble();// compute taxdouble tax = 0;if (status == 0) {   // Compute tax for single filersif (income <= 8350)tax = income * 0.10;else if(income <= 33950)tax = 8350 * 0.10 + (income - 8350) * 0.15;else if(income <= 82250)tax = 8350 * 0.10 + (income - 8350) * 0.15 +(income - 33950) * 0.25;else  if(income <= 171550)tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(82250 - 33950) * 0.25 + (income - 82250) * 0.28;else  if(income <= 372950)tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(82250 - 33950) * 0.25 +(171550 - 82250) * 0.28 +(income - 171550) * 0.33;elsetax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(82250 - 33950) * 0.25 +(171550 - 82250) * 0.28 +(372950 - 171550) * 0.33 + (income - 372950) * 0.35;}else if(status == 1){  // Left as an exercise// Compute tax for married file jointly or qualifying widow(er)}else if(status == 2){  // Left as an exercise}else if(status == 3){  // Left as an exercise}else{System.out.println("Error: invalid status");System.exit(1);}// Display the resultSystem.out.println("Tax is " + (int)(tax * 100) / 100.0);}
}

补充代码:编程练习题3.13 / 程序清单3-5完善版

点击这里快速跳转我的3.15博文,或复制URL到浏览器:

https://blog.csdn.net/weixin_46356698/article/details/119806167

import java.util.Scanner;public class Test3_13 {public static void main(String[] args) {// Create a ScannerScanner input = new Scanner(System.in);// Prompt the user to enter filing statusSystem.out.println("(0-single filer, 1-married jointly or " +"qualifying widow(er), 2-married separately, 3-head of " +"household) Enter the filing status:");int status = input.nextInt();// Prompt the user to enter taxable incomeSystem.out.println("Enter the taxable income:");double income = input.nextDouble();// compute taxdouble tax = 0;if (status == 0) {   // Compute tax for single filersif (income <= 8350)tax = income * 0.10;else if(income <= 33950)tax = 8350 * 0.10 + (income - 8350) * 0.15;else if(income <= 82250)tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(income - 33950) * 0.25;else  if(income <= 171550)tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(82250 - 33950) * 0.25 + (income - 82250) * 0.28;else  if(income <= 372950)tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(82250 - 33950) * 0.25 +(171550 - 82250) * 0.28 +(income - 171550) * 0.33;elsetax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(82250 - 33950) * 0.25 +(171550 - 82250) * 0.28 +(372950 - 171550) * 0.33 + (income - 372950) * 0.35;}else if(status == 1){if (income <= 16700)tax = income * 0.10;else if(income <= 67900)tax = 16700 * 0.10 + (income - 16700) * 0.15;else if(income <= 137050)tax = 16700 * 0.10 + (67900 - 16700) * 0.15 +(income - 67900) * 0.25;else  if(income <= 208850)tax = 16700 * 0.10 + (67900 - 16700) * 0.15 +(137050 - 67900) * 0.25 + (income - 137050) * 0.28;else  if(income <= 372950)tax = 16700 * 0.10 + (67900 - 16700) * 0.15 +(137050 - 67900) * 0.25 +(208850 - 137050) * 0.28 +(income - 208850) * 0.33;elsetax = 16700 * 0.10 + (67900 - 16700) * 0.15 +(137050 - 67900) * 0.25 +(208850 - 137050) * 0.28 +(372950 - 208850) * 0.33 + (income - 372950) * 0.35;}else if(status == 2){if (income <= 8350)tax = income * 0.10;else if(income <= 33950)tax = 8350 * 0.10 + (income - 8350) * 0.15;else if(income <= 68525)tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(income - 33950) * 0.25;else  if(income <= 208850)tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(68525 - 33950) * 0.25 + (income - 68525) * 0.28;else  if(income <= 372950)tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(68525 - 33950) * 0.25 +(208850 - 68525) * 0.28 +(income - 208850) * 0.33;elsetax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(68525 - 33950) * 0.25 +(208850 - 68525) * 0.28 +(372950 - 208850) * 0.33 + (income - 372950) * 0.35;}else if(status == 3){if (income <= 11950)tax = income * 0.10;else if(income <= 45500)tax = 11950 * 0.10 + (income - 11950) * 0.15;else if(income <= 117450)tax = 11950 * 0.10 + (45500 - 11950) * 0.15 +(income - 45500) * 0.25;else  if(income <= 190200)tax = 11950 * 0.10 + (45500 - 11950) * 0.15 +(117450 - 45500) * 0.25 + (income - 117450) * 0.28;else  if(income <= 372950)tax = 11950 * 0.10 + (45500 - 11950) * 0.15 +(117450 - 45500) * 0.25 +(190200 - 117450) * 0.28 +(income - 190200) * 0.33;elsetax = 11950 * 0.10 + (45500 - 11950) * 0.15 +(117450 - 45500) * 0.25 +(190200 - 117450) * 0.28 +(372950 - 190200) * 0.33 + (income - 372950) * 0.35;}else{System.out.println("Error: invalid status");System.exit(1);}// Display the resultSystem.out.println("Tax is " + (int)(tax * 100) / 100.0);}
}

本题代码

public class Test6_15 {public static void main(String[] args) {// 输出表头System.out.println("Taxable\tSingle\tMarried Joint\tMarried\t\tHead of");System.out.println("Income\t\t\tor Qualifying\tSeparate\tHouse hold");System.out.println("\t\t\t\tWidow(er)");System.out.println("——————————————————————————————————————————————");// 输出表内容for (int i = 1; i <= 201;i++){System.out.print(50 * i + 49950);System.out.print("\t" + Math.round(computeTax(0, 50 * i + 49950)));System.out.print("\t\t" + Math.round(computeTax(1, 50 * i + 49950)));System.out.print("\t\t" + Math.round(computeTax(2, 50 * i + 49950)));System.out.print("\t\t" + Math.round(computeTax(3, 50 * i + 49950)) + "\n");}}public static double computeTax(int status, double income){// compute taxdouble tax = 0;if (status == 0) {   // Compute tax for single filersif (income <= 8350)tax = income * 0.10;else if(income <= 33950)tax = 8350 * 0.10 + (income - 8350) * 0.15;else if(income <= 82250)tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(income - 33950) * 0.25;else  if(income <= 171550)tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(82250 - 33950) * 0.25 + (income - 82250) * 0.28;else  if(income <= 372950)tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(82250 - 33950) * 0.25 +(171550 - 82250) * 0.28 +(income - 171550) * 0.33;elsetax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(82250 - 33950) * 0.25 +(171550 - 82250) * 0.28 +(372950 - 171550) * 0.33 + (income - 372950) * 0.35;}else if(status == 1){if (income <= 16700)tax = income * 0.10;else if(income <= 67900)tax = 16700 * 0.10 + (income - 16700) * 0.15;else if(income <= 137050)tax = 16700 * 0.10 + (67900 - 16700) * 0.15 +(income - 67900) * 0.25;else  if(income <= 208850)tax = 16700 * 0.10 + (67900 - 16700) * 0.15 +(137050 - 67900) * 0.25 + (income - 137050) * 0.28;else  if(income <= 372950)tax = 16700 * 0.10 + (67900 - 16700) * 0.15 +(137050 - 67900) * 0.25 +(208850 - 137050) * 0.28 +(income - 208850) * 0.33;elsetax = 16700 * 0.10 + (67900 - 16700) * 0.15 +(137050 - 67900) * 0.25 +(208850 - 137050) * 0.28 +(372950 - 208850) * 0.33 + (income - 372950) * 0.35;}else if(status == 2){if (income <= 8350)tax = income * 0.10;else if(income <= 33950)tax = 8350 * 0.10 + (income - 8350) * 0.15;else if(income <= 68525)tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(income - 33950) * 0.25;else  if(income <= 208850)tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(68525 - 33950) * 0.25 + (income - 68525) * 0.28;else  if(income <= 372950)tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(68525 - 33950) * 0.25 +(208850 - 68525) * 0.28 +(income - 208850) * 0.33;elsetax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(68525 - 33950) * 0.25 +(208850 - 68525) * 0.28 +(372950 - 208850) * 0.33 + (income - 372950) * 0.35;}else if(status == 3){if (income <= 11950)tax = income * 0.10;else if(income <= 45500)tax = 11950 * 0.10 + (income - 11950) * 0.15;else if(income <= 117450)tax = 11950 * 0.10 + (45500 - 11950) * 0.15 +(income - 45500) * 0.25;else  if(income <= 190200)tax = 11950 * 0.10 + (45500 - 11950) * 0.15 +(117450 - 45500) * 0.25 + (income - 117450) * 0.28;else  if(income <= 372950)tax = 11950 * 0.10 + (45500 - 11950) * 0.15 +(117450 - 45500) * 0.25 +(190200 - 117450) * 0.28 +(income - 190200) * 0.33;elsetax = 11950 * 0.10 + (45500 - 11950) * 0.15 +(117450 - 45500) * 0.25 +(190200 - 117450) * 0.28 +(372950 - 190200) * 0.33 + (income - 372950) * 0.35;}else{System.out.println("Error: invalid status");System.exit(1);}return tax;}
}

Java黑皮书课后题第6章:*6.15(金融应用:打印税表)程序清单3-5给出了计算税款的程序。使用下面的方法体编写一个计算税款的方法。使用这个方法编写程序,打印可征税人从50000到60000间隔相关推荐

  1. Java黑皮书课后题第4章:*4.3(几何:估算面积)应用4.1节图中以下地点的GPS位置:Georgia州的Atlanta……计算被这四个城市所围起来的区域面积

    *4.3(几何:估算面积)应用4.1节图中以下地点的GPS位置:Georgia州的Atlanta.Florida州的Orlando.Georgia州的Savannah.North Carolina的C ...

  2. Java黑皮书课后题第10章:*10.1(Time类)设计一个名为Time的类。编写一个测试程序,创建两个Time对象(使用new Time()和new Time(555550000))

    Java黑皮书课后题第10章:*10.1设计一个名为Time的类.编写一个测试程序,创建两个Time对象 题目 程序 代码 Test1.java Test1_Time.java 运行结果 UML 题目 ...

  3. Java黑皮书课后题第9章:*9.6(秒表)设计一个名为StopWatch的类,该类包含……。编写一个测试程序,用于测量使用选择排序对100000个数字进行排序的执行时间

    Java黑皮书课后题第9章:*9.6(秒表)设计一个名为StopWatch的类,该类包含--.编写一个测试程序,用于测量使用选择排序对100000个数字进行排序的执行时间 题目 破题 代码 Test6 ...

  4. Java黑皮书课后题第9章:*9.4(使用Random类)编写一个程序,创建一个种子为1000的Random对象,然后使用nextInt(100)方法显示0到100之间的前50个随机整数

    Java黑皮书课后题第9章:*9.4(使用Random类)编写一个程序,创建一个种子为1000的Random对象,然后使用nextInt方法显示0到100之间的前50个随机整数 题目 赘述 代码 题目 ...

  5. Java黑皮书课后题第9章:*9.3(使用Date类)编写程序创建一个Date对象,设置它的流逝时间分别为...,然后使用toString()方法分别显示上述日期

    Java黑皮书课后题第9章:*9.3(使用Date类)编写程序创建一个Date对象,设置它的流逝时间分别为...,然后使用toString方法分别显示上述日期 题目 代码 思路 代码 题目 代码 思路 ...

  6. Java黑皮书课后题第1章:1.12(以千米计的平均速度)假设一个跑步者1小时40分35秒跑了24英里。编写一个程序显示以每小时为多少千米为单位的平均速度值(1英里等于1.6千米)

    Java黑皮书课后题第1章:1.12(以千米计的平均速度) 题目 题目描述 破题 代码块 修改日志 题目 题目描述 1.12(以千米计的平均速度)假设一个跑步者1小时40分35秒跑了24英里.编写一个 ...

  7. Java黑皮书课后题第1章:*1.11(人口估算)编写一个程序,显示未来5年的每年人口数。假设当前的人口是312 032 486,每年有365天

    Java黑皮书课后题第1章:*1.11(人口估算) 题目 题目描述 破题 代码块 方法评析 为什么print函数内的表达式不能分开 修改日志 题目 题目描述 *1.11(人口估算)编写一个程序,显示未 ...

  8. Java黑皮书课后题第1章:1.7(求π的近似值)编写程序,显示4*(1-1/3+1/5-1/7+1/9-1/11【+1/13】)

    Java黑皮书课后题第1章:1.7(求π的近似值) 题目描述 代码 代码块 评析 修改日志 题目描述 可以使用以下公式计算π: [手动空格]π=4*(1-1/3+1/5-1/7+1/9-1/11+-) ...

  9. Java黑皮书课后题第1章:1.6(数列求和)编写程序,显示1+2+3+4+5+6+7+8+9的结果

    Java黑皮书课后题第1章:1.6(数列求和) 题目 题目描述 槽点 代码 代码块 区分println(x)与println("x") 法1法2选用 修改日志 题目 题目描述 1. ...

  10. Java黑皮书课后题第1章:1.5(计算表达式)编写程序,显示以下式子的结果

    Java黑皮书课后题第1章:1.5(计算表达式) 题目 题目描述 题目槽点 代码 代码块 代码评析与易错点 方法选用 易错点 非常不舒服的运算符前后空格(对新手来讲) 修改日志 题目 题目描述 编写程 ...

最新文章

  1. 前端开发进阶手册.pdf
  2. 关于umask和 find命令
  3. jquery插件学习(六)
  4. 云端计算机可以玩游戏么,手机掌上云电脑是什么?为什么可以玩PC游戏?
  5. 云联惠身份认证得多久_【转发扩散】你完成认证了吗?老来网APP也可以刷脸认证哦!...
  6. 信息学奥赛一本通(1253:抓住那头牛)
  7. 把url地址复制到粘贴板上_写个简单的python爬虫爬取堆糖上漂亮的小姐姐
  8. 算法导论 思考题1-1
  9. zabbix 3.2.3 appliance默认用户名及密码
  10. PAT 乙级 1046. 划拳(15) Java版
  11. Flash Player10一个非常牛的功能SaveBitmap
  12. Spring Security 单点登录系统
  13. 缅甸投资环境及法律政策简介
  14. Office 2016出现加载DLL失败或者库未注册的问题:0x8002801D或者0x80029C4A
  15. Spyder单步调试
  16. tds3014 自动测试软件,TDS3014 Tektronix TDS3014C
  17. 苹果换原装电池_苹果手机换电池客户必看!苹果原装电池科普鉴别!
  18. 从零学习Belief Propagation算法(一)
  19. 助力危化运输升级 欧曼一体化解决方案再写山东危化安全运输新篇
  20. 《系统架构设计》-01-架构和架构师概述

热门文章

  1. linux系统查看性能,linux查看操作系统(linux查看性能)
  2. python连数据库课程设计_python 连接操作 各类数据库
  3. python多线程锁有没有优先级别_全面解析python线程优先级队列(queue)原理
  4. 抢红包神器上线,再也不怕抢不到红包了!
  5. Flink SQL 在字节跳动的优化与实践
  6. 解读云原生下的可观察性发展方向
  7. java安全编码指南之:异常处理
  8. 打散算法的三种解决方案及其选型场景
  9. 腾讯光子《黎明觉醒》技术美术负责人:如何制作超真实的开放世界?
  10. 谈谈战双的战斗机制设计趋同