Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Heavy math sat java writing code question. Need help understanding the thought p

ID: 3853426 • Letter: H

Question

Heavy math sat java writing code question. Need help understanding the thought process and see full explanation on how to get the algebraic manipulation expression's for the first three lines of code eachMonthlyPayment appears.

/*
2. [Critical Thinking] Compute the monthly payment amount and total payoff amount of a loan given the initial amount, apr, and duration
of the loan (number of months).
a. Write a method that takes (amount of debt, apr, number of monthly payments) and returns the amount of each monthly payment.
b. Write a method that takes (amount of debt, apr, number of monthly payments) and returns the total amount paid to payoff the debt.
c. These methods are very similar to the previous two, but they are much more difficult to compute.
*/

public static double monthlyPaymentCalc(double amountOfDebt, double apr, int numOfPayments){
double eachMonthlyPayment = (apr*amountOfDebt) / (1 - Math.pow((1+apr),(-1*numOfPayments)));
eachMonthlyPayment = Math.floor(eachMonthlyPayment*100+0.5) / 100;
eachMonthlyPayment = eachMonthlyPayment / 12;
System.out.println("Your monthly EMI is: " + eachMonthlyPayment);
return eachMonthlyPayment;
}

public static double totalAmountPaidOff(double amountOfDebt, double apr, int numOfPayments){
double totalAmount = monthlyPaymentCalc(amountOfDebt, apr, numOfPayments);
totalAmount = totalAmount*numOfPayments;
System.out.println("Your total amount to be paid off for this loan is: " + totalAmount);
return totalAmount;
}

Explanation / Answer

/**
* Test java program for to find the monthly emi
* and total amount paid.
* */
//Payment.java
public class Payment
{
   public static void main(String[] args)
   {
      
       //set values for principle, apr and numberOfPayments
       double principle=100000;
       double apr=10;
       int numberOfPayments=24;

      
       //calling monthlyPaymentCalc method
       double eachMonthlyPayment=monthlyPaymentCalc(principle,apr,numberOfPayments);
       System.out.printf("Your monthly EMI is: %5.2f " , eachMonthlyPayment);
      
       //calling totalAmountPaidOff method
       double totalAmount=totalAmountPaidOff(principle,apr,numberOfPayments);
       System.out.printf("Your total amount to be paid off for this loan is: %5.2f", totalAmount);
   }

  
   /**
   * The method monthlyPaymentCalc that takes principle of debt, apr(rate)
   * and number of payments and calculates the monthly payment
   * and returns to calling method
   * */
   public static double monthlyPaymentCalc(double amountOfDebt,
           double apr,
           int numOfPayments)
   {
       double monthlInterest = (apr / 12.0) / 100.0;
       double eachMonthlyPayment =
               (monthlInterest * amountOfDebt * (Math.pow((1 + monthlInterest), numOfPayments))/ ((Math.pow((1 + monthlInterest), numOfPayments)) - 1));              

       return eachMonthlyPayment;
   }

  
   /**
   * The method totalAmountPaidOff thata amount of debt, apr
   * and number of payments and calls the method monthlyPaymentCalc
   * and returns the total amount to be paid.
   * */
   public static double totalAmountPaidOff(double amountOfDebt, double apr, int numOfPayments){
       double totalAmount = monthlyPaymentCalc(amountOfDebt, apr, numOfPayments);
       totalAmount = totalAmount*numOfPayments;

       return totalAmount;
   }

}


----------------------------------------------------------------------------------------

Sample Output:

Your monthly EMI is: 4614.49
Your total amount to be paid off for this loan is: 110747.82

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote