[Java] [Exer4] tính lãi xuất ngân hàng


/**
* cusomized by: mathhoang
* Y!M: vietnam_hoangminhnguyen@yahoo.com
* addr: http://mathhoang.blogspot.com
* subject: java tutorials source code
*/
package Exercise3;

public class Exer3 {
private static final int START_RATE = 10;
private static final int NRATES = 6;
private static final int NYEARS = 10;

public static void main(String[] argv) {
double[] interestRate = new double[NRATES];
for (int i = 0; i < interestRate.length; i++) {
interestRate[i] = (START_RATE + i)/ 100.0;
}

double[][] balances = new double[NYEARS][NRATES];

// set initial balances to 10000
for (int i = 0; i < balances[0].length; i++) {
balances[0][i] = 10000;
}

// compue interest for future years
for (int i = 1; i < balances.length; i++){
for (int j = 0; j < balances[i].length; j++){
double oldBalance = balances[i - 1][j];

double interest = oldBalance * interestRate[j];

balances[i][j] = oldBalance + interest;
}

}

// print one row of interest rates
for (int i = 0; i < interestRate.length; i++){
System.out.printf("%9.0f%%", 100 * interestRate[i]);
}

System.out.println();

// print balance table
for (double[] row: balances) {
for (double b: row){
System.out.printf("%10.2f", b);
}

System.out.println();
}

}

}



---
name: nguyen minh hoang
Y!M : vietnam_hoangminhnguyen@yahoo.com
net name: mathhoang

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...