Question
import java.util.*; import java.io.*; import static java.lang.System.*; public class quiz{ public static void main(String args[])throws IOException { Scanner sc = new Scanner (System.in); System.out.println(Enter loan
import java.util.*; import java.io.*; import static java.lang.System.*; public class quiz{ public static void main(String args[])throws IOException { Scanner sc = new Scanner (System.in); System.out.println("Enter loan amount:"); double P = sc.nextDouble(); System.out.println("Enter nominal annual interest:"); double annualInterest = sc.nextDouble(); double r =annualInterest/12; System.out.println("Enter number of years for loan:"); int years = sc.nextInt(); int n = years*12; double pay = P*(r*Math.pow(1+r,n))/(Math.pow(1+r,n)-1); amortiziationScheduleHeader(P); for(int i =1; i<=n;i++) { double interestAmount = r*P; double principalAmount = pay-interestAmount; if((i%25 ==0) || (i==n)) amortiziationScheduleLine(i,pay,interestAmount,principalAmount,(P-principalAmount)); P-=principalAmount; } out.printf(" Amount of interest paid $%,.2f ",_________); } // Prints out the amortiziation schedule header -- do this only once public static void amortiziationScheduleHeader(double b) { out.printf("%s%7s%9s%10s%12s %,45.2f ","Payment","Amount","Interest","Principal","Balance",b); } // Prints out the amortiziation schedule per line -- call this in a loop public static void amortiziationScheduleLine(int x, double a, double b, double c, double d) { out.printf("%4d%,10.2f%,9.2f%,10.2f%,12.2f ", x,a,b,c,d); } } OUTPUT:
Enter loan amount: 20000 Enter nominal annual interest: 0.075 Enter number of years for loan: 5 Payment Amount Interest Principal Balance 20,000.00 25 400.76 80.52 320.24 12,563.33 50 400.76 26.55 374.21 3,873.20 60 400.76 2.49 398.27 0.00
Amount of interest paid $0.00
the part of the code that is bolded is missing something in order to have the output as "Amount of interest paid $4, 045.54" what is missing?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started