Java黑皮书课后题第3章:*3.13(金融应用:计算税款)程序清单3-5给出了计算单身登记人税款的源代码。将程序清单3-5补充完整,从而计算所有登记的婚姻状态的税款
生活随笔
收集整理的這篇文章主要介紹了
Java黑皮书课后题第3章:*3.13(金融应用:计算税款)程序清单3-5给出了计算单身登记人税款的源代码。将程序清单3-5补充完整,从而计算所有登记的婚姻状态的税款
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
*3.13(金融應(yīng)用:計(jì)算稅款)程序清單3-5給出了計(jì)算單身登記人稅款的源代碼。將程序清單3-5補(bǔ)充完整,從而計(jì)算所有登記的婚姻狀態(tài)的稅款
- 題目
- 題目描述
- 程序清單3-5
- 代碼
題目
題目描述
*3.13(金融應(yīng)用:計(jì)算稅款)程序清單3-5給出了計(jì)算單身登記人稅款的源代碼。將程序清單3-5補(bǔ)充完整,從而計(jì)算所有登記的婚姻狀態(tài)的稅款
程序清單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);} }代碼
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);} }總結(jié)
以上是生活随笔為你收集整理的Java黑皮书课后题第3章:*3.13(金融应用:计算税款)程序清单3-5给出了计算单身登记人税款的源代码。将程序清单3-5补充完整,从而计算所有登记的婚姻状态的税款的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java黑皮书课后题第3章:3.12(回
- 下一篇: Java黑皮书课后题第3章:3.14(游