There are 2 files named:
- AnnuityDueGUI.java
- AnnuityDueResultGUI.java
Under AnnuityDueGUI.java, there is this method as below:
=============
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, how to grab the result from the method that I've stated above?both classes are under the same package "GUI". I also did import AnnuityDueGUI.* ;
But still have no idea on how to grab the result from AnnuityDueGUI.java and display it under AnnuityDueResultGUI.java.
Please assist and thanks in advance.
Create
AnnuityDueResultGUI
with a reference to the actualAnnuityDueGUI
instance, then you can access the method:and somewhere inside a method of
AnnuityDueGUI
:You will need a reference to the AnnuityDueGUI object in AnnuityDueResultGUI. So for instance
UPDATE:
Also if you happen to already be constructing the AnnuityDueGUI somewhere else you can just pass the reference to AnnuityDueResultGUI