public class InterestTable3
1:
2: /**
3: Displays a two-dimensional table showing how interest
4: rates affect bank balances.
5: */
6: public class InterestTable3
7: {
8: public static void main(String[] args)
9: {
10: int[][] table = new int[10][6];
11: int row, column;
12: for (row = 0; row < 10; row++)
13: for (column = 0; column < 6; column++)
14: table[row][column] =
15: balance(1000.00, row + 1, (5 + 0.5*column));
16: System.out.println("Balances for Various Interest Rates");
17: System.out.println("Compounded Annually");
18: System.out.println("(Rounded to Whole Dollar Amounts)");
19: System.out.println("Years 5.00% 5.50% 6.00% 6.50% 7.00% 7.50%");
20: System.out.println( );
21: showTable(table);
22: }
23:
24: /**
25: Precondition: The array displayArray has 10 rows and 6 columns.
26: Postcondition: The array contents are displayed with dollar signs.
27: */
28: /**
29: The array displayArray can have any dimensions.
30: Postcondition: The array contents are displayed with dollar signs.
31: */
32: public static void showTable(int[][] displayArray)
33: {
34: int row, column;
35: for (row = 0; row < displayArray.length; row++)
36: {
37: System.out.print((row + 1) + " ");
38: for (column = 0; column < displayArray[row].length; column++)
39: System.out.print("$" + displayArray[row][column] + " ");
40: System.out.println( );
41: }
42: }
43:
44: public static int balance(double startBalance, int years, double rate)
45: {
46: double runningBalance = startBalance;
47: int count;
48: for (count = 1; count <= years; count++)
49: runningBalance = runningBalance*(1 + rate/100);
50: return (int) (Math.round(runningBalance));
51: }
52: }