HW4.22

HW4.22

HW4.22

 import java.util.Scanner;

 public class Solution
 {
     public static void main(String[] args)
     {
         Scanner input = new Scanner(System.in);

         System.out.print("Loan Amount: ");
         double loanAmount = input.nextDouble();
         System.out.print("Number of Years: ");
         int numberOfYears = input.nextInt();
         System.out.print("Annual Interest Rate: ");
         double interestRate = input.nextDouble();

         input.close();

         double monthlyPayment = loanAmount * (interestRate / 12) /
             (1 - 1 / Math.pow(1 + interestRate / 12, numberOfYears * 12));
         System.out.println("Monthly Payment: " + monthlyPayment);
         double totalPayment = monthlyPayment * numberOfYears * 12;
         System.out.println("Total Payment: " + totalPayment);

         System.out.printf("%s\t\t%s\t\t%s\t\t%s", "Payment#", "Interest", "Principal", "Balance");
         System.out.println();

         double interest, principal;
         double balance = loanAmount;

         for(int i = 1; i <= numberOfYears * 12; i++)
         {
             interest = interestRate / 12 * balance;
             principal = monthlyPayment - interest;
             balance -= principal;
             System.out.printf("%d\t\t%f\t\t%f\t\t%f", i, interest, principal, balance);
             System.out.println();
         }
     }
 }
上一篇:基础,杂七杂八(亲测有效)


下一篇:docker-compose使用