Programming Challenge Description: A person has taken a loan of $6000.00 for a f
ID: 3876732 • Letter: P
Question
Programming Challenge Description: A person has taken a loan of $6000.00 for a fixed annual interest rate of 6% for 5 years with no down payment. The monthly payment has been fixed at $116.00 for entire term of the loan. Here is the formula to calculate monthly fixed payment: (NOTE: See attachment) P = (monthly rate * Loan amount) / (1- (1+monthly nterest rate)A-n) Here n is no of payment periods. Write a program to: 1. To calculate monthly payment 2. To print out monthly payment and total interest payment for the duration of loan rounded to its nearest integer Input: 6000 5 6 0 Output: $116.00~$960] Test 1 Test Input B 30000 10 6 5000 Expected Output H $277.55 $8306Explanation / Answer
The code is
import java.util.Scanner;
import java.util.StringTokenizer;
public class Interest
{
public static double monthlyPayment(double amt,double year,double rate,double payment)
{
amt-=payment;
double P=(rate*amt/1200)/(1-Math.pow((1+rate/1200),-1*year*12));
return Math.round(P);
}
public static void main(String[] args)
{
Scanner in =new Scanner(System.in);
String s=in.nextLine();
StringTokenizer st= new StringTokenizer(s,"~");
double rate,year,payment,amt;
amt=Double.parseDouble(st.nextToken());
year=Double.parseDouble(st.nextToken());
rate=Double.parseDouble(st.nextToken());
payment=Double.parseDouble(st.nextToken());
double mP=monthlyPayment(amt, year, rate, payment);
System.out.print(mP+"~");
amt-=payment;
System.out.println(mP*year*12-amt);
}
}
The output is
6000~5~6~0
116.0~960.0
The other output is
30000~10~6~5000
278.0~8360.0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.