日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

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

發布時間:2024/7/23 java 34 豆豆

*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间隔的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。