The problem I am having is I want to input the parameters to the Compounding class that then gives me a result and then by using a boolean check in the main tell me if each parameter is correct. Basically a form of testing that my professor is having us do in class. My problem is I cant get a boolean to pass to the main because of my double variables. I am kinda stuck on what to do and cannot figure out how to fix this.
package compoundInterest; package compoundInterest;
public class Main {
public static void main(String[] args) {
CompInterest Debt = new CompInterest();
System.out.println("lets see if this works");
System.out.printf("$%.2f",Debt.TotalCompInterest(10,10_000,3.5));
}
public boolean testYear() {
CompInterest T = new CompInterest();
boolean Test = T.TotalCompInterest(10, 10_000, 3.5);
System.out.println("results of test #1 = " + Test );
if(Test == true){
System.out.println("The test passed!");
} else {
System.out.println("The test failed!");
}
}
} public class CompInterest {
public boolean TotalCompInterest
(double year, double principle, double rate) {
double amount = 0;
double timesComp = 1;
rate=(1+rate/100);
for(int i=0;i<year;i++)
timesComp*=rate;
amount=principle*timesComp;
double CompInt = amount-principle;
return true;
}
}
Aucun commentaire:
Enregistrer un commentaire