Account totalDeposits;
float [][]data = {
{
50000, 0.25, 6
}
, {
12000, 0.5, 10
}
, {
30000, 0.75, 12
}
};
String [] name = {
"Ken", "Anna", "Fiona"
};
for (int i = 0; i<data.length; i++) {
totalDeposits = new Account (data[i][0], data[i][1], data[i][2]);
println ("Money of "+(name[i])+" that deposited in the bank for "+(data[i][2])+" months is "+(totalDeposits.Calculate_totalMoney())+" Baht.");
}
}
class Account {
float capital;
float increase;
float totalMonth;
Account (float capital, float increase, float totalMonth) {
this.capital = capital;
this.increase = increase;
this.totalMonth = totalMonth;
}
float Calculate_totalMoney () {
float percentIncrease = (increase/100);
for (int i =1; i<=totalMonth; i++) {
float onlyIncrease = (capital*percentIncrease);
capital = onlyIncrease+capital;
}
return capital;
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น