I'm making a program and I can't get it to display the results properly in the displayInterest method in the InterestCalculatorTest class.
InterestCalculator7 Class
public class InterestCalculator7 { // Class Level Variables (Data Fields / Properties) public double principalAmount; public double interestRate; public int term1; // ** Constructors ** // No-Argument constructor public InterestCalculator7() { this.principalAmount = 0.0; this.interestRate = -1.0; this.term1 = 0; } public InterestCalculator7(double principalAmount, double interestRate, int term1) { this.principalAmount = principalAmount; this.interestRate = interestRate; this.term1 = term1; } // ** Methods ** public double calculateSimpleInterest() { double calculateSimpleInterest = ((principalAmount)*(interestRate/100.0)*(term1/12.0)); return calculateSimpleInterest; } public double calculateCompoundInterest(double term1) { double calculateCompoundInterest = (principalAmount*Math.pow((1.0+((interestRate/100.0)/term1)),(term1*(term1/12.0))))-principalAmount; return calculateCompoundInterest; } }
InterestCalculatorTest class
public class InterestCalculatorTester { public static void main(String[] args) { double principal; double interest; int term; do{ principal = getPrincipalAmount(); interest = getInterestRate(); term = getTerm(); double calculationType = getCalculationType(principal,interest,term); InterestCalculator7 interestCalculator = new InterestCalculator7(principal, interest, term); if (calculationType == 1) { calculationType = interestCalculator.calculateSimpleInterest(); displayInterest(interestCalculator, "Simple", calculationType); } else if (calculationType == 2) { calculationType = interestCalculator.calculateCompoundInterest(12.0); displayInterest(interestCalculator, "Monthly", calculationType); } else if (calculationType == 3) { calculationType = interestCalculator.calculateCompoundInterest(365.0); displayInterest(interestCalculator, "Daily", calculationType); } else { calculationType = interestCalculator.calculateCompoundInterest(52.0); displayInterest(interestCalculator, "Weekly", calculationType); } } while (askYesNo("Calculate another loan interest (Yes/No)")); System.out.print("Thanks for using Interest Calculator!"); } /** Round **/ public double round(double numb1, double numb2) { double round = ((double) Math.round(numb1*(Math.pow(10, numb2)))/(Math.pow(10, numb2)));; return round; } /** display interest **/ public static void displayInterest(InterestCalculator7 object, String type, double calculationType) { System.out.println("Principal Amount Interest Rate Term Calculation Type Calculated Interest Total Repayment"); System.out.println("---------------- ------------- ---- ---------------- ------------------- ---------------"); System.out.print(getPrincipalAmount()+" "); System.out.print(+getInterestRate()+" "); System.out.print(+getTerm()+" "); System.out.print(+type+" "); System.out.print(+calculationType+" "); System.out.println(+(getPrincipalAmount() + calculationType)); } /** Get principal amount **/ public static double getPrincipalAmount() { Scanner input = new Scanner(System.in); double numb2 = 1; do{System.out.print("Enter Loan Amount: "); numb2 = input.nextDouble(); if(numb2 > 0); else{ System.out.println("Data Error: Loan amount must be greater than zero. You entered " +numb2); } }while (numb2 < 0); return numb2; } /** Get interest rate **/ public static double getInterestRate() { Scanner input = new Scanner(System.in); double numb2=1; do{System.out.print("Enter Yearly Interest Rate (1 to 100 percent): "); numb2 = input.nextDouble(); double getInterestRate = 0; if (numb2 >= 0 && numb2 <= 100) getInterestRate = numb2; else{ System.out.println("Data Error: Interest rate must be greater than or equal to zero and less than or equal to 100. You entered " +numb2); } }while (numb2 <= 0 || numb2 >= 100); return numb2; } /** Get term **/ public static int getTerm() { Scanner input = new Scanner(System.in); int numb2=1; do{System.out.print("Enter the Term (in months): "); numb2 = input.nextInt(); double getTerm = 0; if (numb2 > 0) getTerm = numb2; else{ System.out.println("Data Error: Loan amount must be greater than zero. You entered " +numb2); } }while (numb2 <= 0); return numb2; } /** Get calculation type **/ public static double getCalculationType(double numb1, double numb2, double numb3) { Scanner input = new Scanner(System.in); int type; do{ System.out.print("Enter Interest Calculation Type (1 – Simple, 2 – Monthly Compounded, 3 – Daily Compounded, 4 - Weekly Compounded):"); type = input.nextInt(); double principle = numb1; double interest= numb2; double term= numb3; } while (type !=1 && type !=2 && type !=3 && type !=4); return type; } /**ask yes or no **/ public static boolean askYesNo(String question) { Scanner input = new Scanner(System.in); String enteredText; boolean isAnswerValid; do{ isAnswerValid = false; System.out.println(question); enteredText = input.nextLine(); if (enteredText.length() > 0) { enteredText = enteredText.toUpperCase(); if(enteredText.equals("YES") || enteredText.equals("Y") || enteredText.equals("NO") || enteredText.equals("N")) { isAnswerValid = true; } } if(isAnswerValid == false) { System.out.println("Please enter 'Yes' or 'No'?"); } } while(isAnswerValid == false); if(enteredText.equals("YES") || enteredText.equals("Y")) { return true; } return false; } }