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

When you borrow money to buy a house, a car, or for some other purpose, you repa

ID: 3623376 • Letter: W

Question

When you borrow money to buy a house, a car, or for some other purpose, you repay the loan by making periodic payments over a certain time. Of course the lending company will charge interest on the loan. Every periodic payment consists of the interest on the loan and the payment toward the principal amount. To be specific, suppose your borrow RM1000 at the interest rate of 7.2% per year and the payments are monthly. Suppose that your monthly payment is RM25. The interest is 7.2% per year and the payments are monthly, so the interest rate per month is 7.2/12=0.6%. The first month interest on the RM1000 is 1000*0.006 = 6. Because payment is RM25 and interest for the first month is RM6, the payment toward the principal amount is 25 – 6 = 19. This means that after making the first payment, the loan amount is 1000 – 19 = 981.

For the second payment, the interest is calculated on RM981. So the interest for the second month is 981 * 0.006 = 5.886, that is approximately RM5.89. This implies, that the payment toward the principal is 25 – 5.89 = 19.11, and the remaining balance after the second payment is 981 – 19.11 = 961.89. This process is repeated until the loan is paid.

Write a program that accepts as input the loan amount, the interest rate per year, and the monthly payment. Enter the interest rate as a percentage. For example, if the interest rate is 7.2% per year, then enter 7.2. The program then outputs the number of months it would take to repay the loan. (Note: If the monthly payment is less than the first month’s interest, then after each payment, the loan amount will increase. In this case, the loan amount could not be repaid.) You must tell the user the minimum monthly payment before asking for the monthly payment. The last payment might be more than the remaining loan amount and interest on it. In this case, output the loan amount before the last payment and the actual amount of the last payment. Also output the total interest paid.

Explanation / Answer

please rate - thanks

import java.util.*;
public class loan
{public static void main(String [] args)
   {double principal, rate, mrate, mpay, factor, interest=0,totint=0,min;
   int cnt=1;
    Scanner in=new Scanner(System.in);
   System.out.print("Enter the principal of the loan: ");
   principal=in.nextDouble();
    System.out.print("What is the Annual Interest Rate? ");
   rate=in.nextDouble();
    mrate=rate/100/12;
   min=principal*mrate;
    System.out.printf("Your minimum monthly payment is %.2f ",min);
    System.out.print("What is the monthly payment? ");
   mpay=in.nextDouble();
    while(mpay<min)
         {System.out.printf("Must be at least %.2f ",min);
           System.out.print("What is the monthly payment? ");
         mpay=in.nextDouble();
         }
   System.out.printf("Principal: RM %.2f ",principal);
   System.out.printf("Annual Interest Rate: %.2f%% ",rate);
   System.out.printf("Monthly Payment: %.2f ",mpay);  
    while(principal>mpay)
     {interest=principal*((rate/100)/12);
       totint+=interest;
        principal=principal+interest-mpay;
    cnt++;
      }
   interest=principal*((rate/100)/12);
    totint+=interest;
   System.out.printf("Final Payment: RM%6.2f ",principal+interest);
    System.out.printf("Total interest paid RM%6.2f ",totint);
    System.out.println("Total number of payments: "+(cnt));
    }  
   }
  

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