Java黑皮书课后题第10章:***10.8(金融:Tax类)编程练习题8.12使用数组编写一个计算税款的程序。设计一个名为Tax类,该类包含下面的实例数据域
生活随笔
收集整理的這篇文章主要介紹了
Java黑皮书课后题第10章:***10.8(金融:Tax类)编程练习题8.12使用数组编写一个计算税款的程序。设计一个名为Tax类,该类包含下面的实例数据域
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
***10.8(金融:Tax類)編程練習題8.12使用數(shù)組編寫一個計算稅款的程序。設計一個名為Tax類,該類包含下面的實例數(shù)據(jù)域
- 題目
- 程序解釋
- 代碼
- Test8.java
- Test8_Tax.java
- 運行實例
- UML
題目
表3-2:
| 10% | $0~8350 | $0~$16700 | $0~$8350 | $0~$11950 |
| 15% | $8351~$33950 | $16701~$67900 | $8351~$33950 | $11951~$45500 |
| 25% | $33951~$52250 | $67901~$137050 | $33951~$68525 | $45501~$117450 |
| 28% | $52251~$171550 | $137051~$208850 | $68526~$104425 | $117451~$190200 |
| 33% | $171551~$372950 | $208851~$372950 | $104426~$186475 | $190201~$372950 |
| 35% | $372951+ | $372951+ | $186476+ | $372951+ |
點擊這里查看編程練習題8.12
程序解釋
Test8.java:測試程序
Test8_Tax.java:構造程序
代碼
Test8.java
public class Test8 {public static void main(String[] args) {// 2001年int[][] arr0 = {{27050, 65550, 136750, 297350},{45200, 109250, 166500, 297350},{22600, 54625, 83250, 148675},{36250, 93650, 151650, 297350}};double[] rate0 = {0.15, 0.275, 0.305, 0.355, 0.391};// 打印表頭System.out.print("2001年\n\t");for (int i = 50000 ; i <= 60000 ; i += 1000){System.out.print(i + "\t");}// 計算稅費for (int a = 0 ; a < 4 ; a++){System.out.print("\n" + a + "\t");for (int b = 50000 ; b <= 60000 ; b += 1000){Test8_Tax t1 = new Test8_Tax(a, arr0, rate0, b);System.out.printf("%d\t", (int)t1.getTax());}}// 2009年int[][] arr1 = {{8350, 33950, 52250, 171550, 372950},{16700, 33950, 68525, 104425, 186475},{8350, 33950, 68525, 104425, 186475},{11950, 45500, 117450, 190200, 372950}};double[] rate1 = {0.1, 0.15, 0.25, 0.28, 0.33, 0.35};// 打印表頭System.out.print("\n2009年\n\t");for (int i = 50000 ; i <= 60000 ; i += 1000){System.out.print(i + "\t");}// 計算稅費for (int a = 0 ; a < 4 ; a++){System.out.print("\n" + a + "\t");for (int b = 50000 ; b <= 60000 ; b += 1000){Test8_Tax t2 = new Test8_Tax(a, arr0, rate0, b);System.out.printf("%d\t", (int)t2.getTax());}}} }Test8_Tax.java
public class Test8_Tax {public static final int SINGLE_fLER = 0;public static final int MARRIED_JOINTLY_OR_QUALIFYING_WIDOW = 1;public static final int MARRIED_SEPARATELY = 2;public static final int HEAD_OF_HOUSEHOLD = 3;int filingStatus;int[][] brackets;// = {// {27050, 65550, 136750, 297350},// {45200, 109250, 166500, 297350},// {22600, 54625, 83250, 148675},// {36250, 93650, 151650, 297350},// };double[] rates;// = {0.15, 0.275, 0.305, 0.355, 0.391};double taxableIncome;public int getFilingStatus() {return filingStatus;}public void setFilingStatus(int filingStatus) {this.filingStatus = filingStatus;}public int[][] getBrackets() {return brackets;}public void setBrackets(int[][] brackets) {this.brackets = brackets;}public double[] getRates() {return rates;}public void setRates(double[] rates) {this.rates = rates;}public double getTaxableIncome() {return taxableIncome;}public void setTaxableIncome(double taxableIncome) {this.taxableIncome = taxableIncome;}public double getTax(){int index = 0;for (int i = 0 ; i < brackets[filingStatus].length ; i++){if (brackets[filingStatus][i] > taxableIncome)index = i;}return rates[index] * taxableIncome;}public Test8_Tax(){}public Test8_Tax(int filingStatus, int[][] brackets, double[] rates, double taxableIncome){this.filingStatus = filingStatus;this.taxableIncome = taxableIncome;this.brackets = brackets;this.rates = rates;} }運行實例
2001年50000 51000 52000 53000 54000 55000 56000 57000 58000 59000 60000 0 17750 18105 18460 18815 19170 19525 19880 20235 20590 20945 21300 1 17750 18105 18460 18815 19170 19525 19880 20235 20590 20945 21300 2 17750 18105 18460 18815 19170 19525 19880 20235 20590 20945 21300 3 17750 18105 18460 18815 19170 19525 19880 20235 20590 20945 21300 2009年50000 51000 52000 53000 54000 55000 56000 57000 58000 59000 60000 0 17750 18105 18460 18815 19170 19525 19880 20235 20590 20945 21300 1 17750 18105 18460 18815 19170 19525 19880 20235 20590 20945 21300 2 17750 18105 18460 18815 19170 19525 19880 20235 20590 20945 21300 3 17750 18105 18460 18815 19170 19525 19880 20235 20590 20945 21300UML
總結
以上是生活随笔為你收集整理的Java黑皮书课后题第10章:***10.8(金融:Tax类)编程练习题8.12使用数组编写一个计算税款的程序。设计一个名为Tax类,该类包含下面的实例数据域的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java黑皮书课后题第10章:**10.
- 下一篇: Java黑皮书课后题第10章:**10.