I am working on developing a PV schedule in Java. The below else statement is fo
ID: 3598367 • Letter: I
Question
I am working on developing a PV schedule in Java. The below else statement is for an annuity/loan. Can you help me fix my f instanceof Pv?
if (f instanceof Pv) {
//set up virtual table to display Pv full schedule
String[] cols={"Month","Discount","Present Value"};
String [] []t=new String[f.getTerm()][3];
mod=new DefaultTableModel(t, cols);
sched=new JTable(mod);
for (int i=0;i<f.getTerm();i++) {
sched.setValueAt(i+1, i, 0);
//sched.setValueAt(c.format(f.getBegBal(i+1)), i, 1);
sched.setValueAt(c.format(f.getPrinFactor(i+1)), i, 1);
//sched.setValueAt(c.format(f.getRate()), i, 3);
//sched.setValueAt(c.format(f.getRateFactor(i+1)), i, 4);
sched.setValueAt(c.format(f.getEndBal(i+1)), i, 2);
}
}
else //set up virtual table to display Annuity and Loan
{
//set up the colum heading
String[] cols={"Month",f.getBegBalDesc(),f.getPrinFactorDesc(),Financials.RATE_DESC,
f.getRateFactorDesc(),f.getResultDesc()};
String [] []t=new String[f.getTerm()][6];
mod=new DefaultTableModel(t, cols);
sched=new JTable(mod);
for (int i=0;i<f.getTerm();i++) {
sched.setValueAt(i+1, i, 0);
sched.setValueAt(c.format(f.getBegBal(i+1)), i, 1);
sched.setValueAt(c.format(f.getPrinFactor(i+1)), i, 2);
sched.setValueAt(c.format(f.getRate()), i, 3);
sched.setValueAt(c.format(f.getRateFactor(i+1)), i, 4);
sched.setValueAt(c.format(f.getEndBal(i+1)), i, 5);
}
Explanation / Answer
if (f instanceof Pv) {
//set up virtual table to display Pv full schedule
String[] cols={"Month","Discount","Present Value"};
String [] []t=new String[f.getTerm()][3];
mod=new DefaultTableModel(t, cols);
sched=new JTable(mod);
for (int i=0;i<f.getTerm();i++) {
sched.setValueAt(i+1, i, 0);
//sched.setValueAt(c.format(f.getBegBal(i+1)), i, 1);
sched.setValueAt(c.format(f.getPrinFactor(i+1)), i, 1);
//sched.setValueAt(c.format(f.getRate()), i, 3);
//sched.setValueAt(c.format(f.getRateFactor(i+1)), i, 4);
sched.setValueAt(c.format(f.getEndBal(i+1)), i, 2);
}
}
else //set up virtual table to display Annuity and Loan
{
//set up the colum heading
String[] cols={"Month",f.getBegBalDesc(),f.getPrinFactorDesc(),Financials.RATE_DESC,
f.getRateFactorDesc(),f.getResultDesc()};
String [] []t=new String[f.getTerm()][6];
mod=new DefaultTableModel(t, cols);
sched=new JTable(mod);
for (int i=0;i<f.getTerm();i++) {
sched.setValueAt(i+1, i, 0);
sched.setValueAt(c.format(f.getBegBal(i+1)), i, 1);
sched.setValueAt(c.format(f.getPrinFactor(i+1)), i, 2);
sched.setValueAt(c.format(f.getRate()), i, 3);
sched.setValueAt(c.format(f.getRateFactor(i+1)), i, 4);
sched.setValueAt(c.format(f.getEndBal(i+1)), i, 5);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.