0

There are 3 files:

1. Annuuity.java
2. AnnuityDueGUI.java  // GUI for Annuity Due
2. AnnuityDueResultGUI.java  //GUI for the result

Under AnnuityDueGUI.java:

public double calculateFADGUI(){
        //FVA = A{[(1+i)^n – 1] / i} (1+i)
        String amountStr = amount.getText() ;  //convert string to double
        dAmount = Double.parseDouble(amountStr) ;
        String iStr = iText.getText() ;
        dInterest = Double.parseDouble(iStr) ;
        String periodStr = period.getText() ;
        dPeriod = Double.parseDouble(periodStr) ;
        iPeriod = (int)dPeriod ;
        due = new Annuity(dAmount, dInterest, iPeriod) ;
        System.out.println(due.calculateFAD()) ;
        return due.calculateFAD() ;  //calculateFAD() is under Annuity.java
        }

Under AnnuityDueResultGUI.java:

AnnuityDueGUI due ;

public AnnuityDueResultGUI(AnnuityDueGUI due){  //1st solution failed
    this.due = due ;
}
public void grabResult(){  //1st solution failed
   result = this.due.calculateFADGUI() ;
}

public AnnuityDueResultGUI(){

    JPanel p6 = new JPanel() ;
    p6.setLayout(new GridLayout(2, 1)) ;
    p6.add(new JLabel("you will have approximately $" + result)) ;
    // other codes 
}

From AnnuityDueGUI.java I am able to see the result of due.calculateFAD() . But, I would like to display the result under AnnuityDueResultGUI.java

I already did put them under a package named 'GUI' and also did import AnnuityDueGUI.java and Annuity.java.

I did the steps that was recommended in this forum on my other same question using unregisterd user. But, it did not work(the passed result is 0). That's why I'm posting the same question again with more details.

Please assist and thank you in advance.

1 Answer 1

1

I think you forgot to call the grabResult() method.

public AnnuityDueResultGUI(AnnuityDueGUI due){  
    this.due = due ;
    grabResult(); // calling this will store the value in the "result" instance variable

    JPanel p6 = new JPanel() ;
    p6.setLayout(new GridLayout(2, 1)) ;
    p6.add(new JLabel("you will have approximately $" + result)) ;
    // other codes 
}

private void grabResult(){  
   result = this.due.calculateFADGUI() ;
}

On a side note, you should avoid calling public methods of a non-final class in your constructor.

1
  • thanks for the reply. I did follow your suggestion. But, the result is still 0. Aug 12, 2010 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.